When I write jest test case, it throw error. my project used vant UI, but when I not use vant UI test,it's run well. I looked for the answer on the Internet, but I couldn't do it all the time。 Has anyone solved similar problems?
babel.config.js:
module.exports = {
presets: [
"@vue/cli-plugin-babel/preset",
],
plugins: [
[
"import",
{
libraryName: "vant",
libraryDirectory: "es",
style: (name) => `${name}/style/less`,
},
"vant",
],
],
sourceMaps: true,
env: {
test: {
presets: [
['@vue/cli-plugin-babel/preset'],
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
plugins: [
[
"import",
{
libraryName: "vant",
libraryDirectory: "es",
style: (name) => {
return `${name}/style/less`
},
},
"vant",
],
],
},
},
};
jest.config.js:
module.exports = {
preset: "@vue/cli-plugin-unit-jest/presets/typescript-and-babel",
transform: {
".*\\.(tsx)$": "ts-jest",
"^.+\\.js": "babel-jest",
"^.+\\.vue$": "vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
},
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1",
},
moduleFileExtensions: [
"js",
"json",
"ts",
"tsx",
"vue"
],
// collectCoverage
// moduleNameMapper: {
// // "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
// "\\.(css|less)$": "identity-obj-proxy"
// }
};
what errors enter image description here