DEV Community

Discussion on: Add testing to Vite

Collapse
 
soetz profile image
Sœtz - Simon Lecutiez • Edited

Hey! Thanks a load for this, but it seems it doesn’t work for me… The error I got says Cannot find module './xxx.vue' or its corresponding type declarations.. I tried searching for ways to fix this but couldn’t understand what’s wrong. :( It’s such a shame because Vite was a nice experience until then.

Collapse
 
webmaplee profile image
webmapLee

i have same problem, just use @vue/vue3-jest

Collapse
 
geminii profile image
Jimmy

I got the same error. How to fix this ?

Collapse
 
webmaplee profile image
webmapLee

just use vue-jest@next don't use vue-jest/next or vue3-jest ,it's a issues of Version compatibility, then config in jest.config.js as follow:

module.exports = {
moduleFileExtensions: ['js', 'ts', 'json', 'vue'],
transform: {
'^.+\.ts$': 'ts-jest',
'^.+\.vue$': '@vue/vue3-jest',
},
testEnvironment: 'jsdom',
// transformIgnorePatterns: ['node_modules/(?!variables/.*)'],
}

remember set the testEnvironment to 'jsdom'

Collapse
 
sonicoder profile image
Gábor Soós

Can you share code alongside the error message?

Collapse
 
soetz profile image
Sœtz - Simon Lecutiez

I tried it again, and I think I got it right this time. Thanks!

Collapse
 
odinkraa profile image
xl ama slim fit

I had the same problem, got it to working by downing
jest version to 26.6.3
ts-jest to 26.5.6

here is my package.json

{
"name": "vite-testing",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"serve": "vite preview",
"test": "jest src"
},
"dependencies": {
"vue": "^3.2.13"
},
"devDependencies": {
"@types/jest": "^26.0.2",
"@vitejs/plugin-vue": "^1.9.0",
"@vue/test-utils": "^2.0.0-rc.15",
"jest": "^26.6.3",
"ts-jest": "^26.5.6",
"typescript": "^4.4.3",
"vite": "^2.5.10",
"vue-jest": "^5.0.0-alpha.10",
"vue-tsc": "^0.3.0"
}
}

Collapse
 
lemredd profile image
lemredd

This also worked for me

Collapse
 
odinkraa profile image
xl ama slim fit

the problem now is it's passing while it shouldn't lol