question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue tsx component type definition 'any' in typescript project issue when unit-testing.

See original GitHub issue

Problem: I create vue 3 TSX project with default selection from vue cli, typescript, jest. When testing my component, it not show type define on my component in vs code intellisense. It show up as any. It not right since I am use typescript.

This issue just recently like 1 week or 2. Like 2 week ago, I create vue 3 typescript with jest enable. And it work and show up type define component on my IDE then. Now I just create new project vue 3. it not show type define on my component on my IDE.

Imgur

Reproducible Case

  • vs code IDE
  • Create new vue 3 project with vue cli
  • select typescript, jest

Sample code with typescript, jest enable. create App.tsx and in example.spec.ts file with follow code:

// App.tsx
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'App',
  data() {
    return {
      timer: null
    }
  },
  methods: {
    handleSendMessage() {
      console.log('handleSendMessage()')
    }
  },
  render() {
    return (
      <div>
        App component in tsx
      </div>
    )
  }
})
// example.spec.ts
import { shallowMount } from '@vue/test-utils'
import App from '@/App' // same problem if use relative import like ../../scr/App

describe('App.vue', () => {
    it('testing', () => {
      const wrapper = shallowMount(App)
      wrapper.vm.  // <--- after . my IDE would show all property on this component like all methods, data, etc. It do not show up here.
    })
})

Side note: it did work before on vue 3 project. I also test on vue 2 tsx project. it work fine there.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
lmiller1990commented, Nov 22, 2020

Right, that makes sense… derp. Thanks for picking this up @pikax.

We will fix the types and remove the class component dependency in the next release.

0reactions
pikaxcommented, Nov 21, 2020

You can fix this by running: npm i vue-class-component@8.0.0-beta.4

The cause is that dependency is not shipped with vue-test-utils, I’ll have a look on the types

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use typescript correctly? · Issue #255 · vuejs/vue-test ...
The main issue, is that wrapper.vm is typed as a generic Vue instance. This should probably typed as the component instance in use....
Read more >
Getting error in unit test from new vue 3 project generated by CLI
Even though I've used Javascript for a long time I am new to typescript and unable to read the error properly/make sense of...
Read more >
How to use Vue 3 with TypeScript - LogRocket Blog
First, we'll set up a new Vue project with TypeScript using the code ... we can use to define Vue components with full...
Read more >
Testing JSX components with Jest in NuxtJS - Damir's Corner
Initial NuxtJS configuration for writing Jest tests in TypeScript for JSX components is incomplete. The guidance in error messages takes you ...
Read more >
Using with TypeScript - Vue Test Utils
In this guide, we'll walk through how to setup a testing setup for a TypeScript project using Jest and Vue Test Utils from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found