在升级到Vue 3之后,在GitHub操作中运行单元测试时,会得到以下错误:
> vue-cli-service test:unit
● Validation Error:
An unknown error occurred in @vue/cli-plugin-unit-jest:
Cannot resolve "@vue/vue3-jest" module. Please make sure you have installed "@vue/vue3-jest" as a dev dependency.GitHub操作脚本使用npm ci作为其安装依赖项的前一步,测试命令vue-cli-service test:unit在本地工作。
我的package.json有:
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.16.5",
"@babel/plugin-proposal-optional-chaining": "^7.14.5",
"@storybook/addon-a11y": "^6.4.12",
"@storybook/addon-actions": "^6.4.12",
"@storybook/addon-essentials": "^6.4.12",
"@storybook/addon-links": "^6.4.12",
"@storybook/addon-storysource": "^6.4.12",
"@storybook/vue": "^6.4.12",
"@testing-library/dom": "^7.31.2",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/user-event": "^13.2.1",
"@testing-library/vue": "^6.4.2",
"@vue/babel-preset-app": "latest",
"@vue/cli-plugin-babel": "~5.0.0-rc.2",
"@vue/cli-plugin-e2e-cypress": "~5.0.0-rc.2",
"@vue/cli-plugin-eslint": "~5.0.0-rc.2",
"@vue/cli-plugin-router": "~5.0.0-rc.2",
"@vue/cli-plugin-unit-jest": "^5.0.0-rc.1",
"@vue/cli-service": "~5.0.0-rc.2",
"@vue/cli-shared-utils": "^4.5.10",
"@vue/eslint-config-airbnb": "^6.0.0",
"@vue/preload-webpack-plugin": "^1.1.2",
"@vue/test-utils": "^2.0.0-rc.18",
"@vue/vue3-jest": "^27.0.0-alpha.4",
...
"babel-loader": "^8.2.2",
...
"jest": "^27.1.0",
"jest-extended": "^0.11.5",
"jest-junit": "^8.0.0",
...
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
},我的jest.config.js在使用@vue/vue3-jest中匹配文档:
"transform": {
"^.+\\.vue$": "@vue/vue3-jest"
},发布于 2022-12-03 13:25:47
请试试看
# Vue 2
npm install --save-dev @vue/vue2-jest@28 # (use the appropriate version)
yarn add @vue/vue2-jest@28 --dev
# Vue 3
npm install --save-dev @vue/vue3-jest@28 # (use the appropriate version)
yarn add @vue/vue3-jest@28 --devhttps://stackoverflow.com/questions/70734715
复制相似问题