Vue tsx component type definition 'any' in typescript project issue when unit-testing.
See original GitHub issueProblem: 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.
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:
- Created 3 years ago
- Reactions:1
- Comments:11 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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