I have an error when I want to run Jest because of moduleNameMapper
settings.
I tried several methods, but nothing changes.
To reproduce:
npm install
npm run test
Since you're using Vue CLI, you should use @vue/cli-plugin-unit-jest
, which can be added to your Vue CLI project with this command:
vue add unit-jest
This will also add a <rootDir>/test
directory with a sample test, but that doesn't fit your project's test file pattern, which places *.spec.js
adjacent to the source files.
To adapt the result to your project:
<rootDir>/test
(as it would be unused, and because it points to a nonexistent HelloWorld.vue
)jest
config in package.json
to be:{
"jest": {
"preset": "@vue/cli-plugin-unit-jest",
"testMatch": [
"**/src/**/*.spec.[jt]s?(x)"
]
}
}
test
NPM script, since @vue/cli-plugin-unit-jest
automatically adds its own test:unit
script, which must be used instead (i.e., use npm run test:unit
).