[英]jest ReferenceError: Vue is not defined
We are introducing Jest to an existing project.我们正在将 Jest 引入现有项目。
However, I wrote an example test code.但是,我写了一个示例测试代码。 The above error occurred.出现上述错误。
ReferenceError: Vue is not defined
1 | import User from "../components/modal/ad/AdAdd";
> 2 | import { mount } from "@vue/test-utils";
| ^
3 |
4 | describe("user component", () => {
5 | let wrapper;
How can I solve this??我该如何解决这个问题?
//User.test.js
import User from "../components/modal/ad/AdAdd";
import { mount } from "@vue/test-utils";
describe("user component", () => {
let wrapper;
beforeEach(() => {
wrapper = mount(User);
});
test("render", () => {
expect(wrapper.vm.oSid).toBe(0);
});
});
export default {
data() {
return {
Sid: 0,
deleteList: [],
};
},
//package.json
"dependencies": {
"eslint-plugin-jest": "^26.2.2",
"vue": "^2.6.11",
"vuetify": "^2.4.0",
"vuex": "^3.4.0",
},
"devDependencies": {
"@babel/core": "^7.18.0",
"@babel/preset-env": "^7.18.0",
"@types/jest": "^27.5.1",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-service": "^3.0.5",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/test-utils": "^2.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^28.1.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^6.2.2",
"jest": "^28.1.0",
"jest-environment-jsdom": "^28.1.0",
"speed-measure-webpack-plugin": "^1.5.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"vue-cli-plugin-vuetify": "~2.4.0",
"vue-jest": "^3.0.7",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.7.0"
}
I just mounted it, but it says the view is undefined.我刚刚安装它,但它说视图未定义。 I don't know how to solve it.我不知道如何解决它。
What's wrong??怎么了??
I haven't been able to solve the above error for several days.我已经好几天没能解决上述错误了。
I want to solve it.我想解决它。 Any help would be appreciated.任何帮助,将不胜感激。
I had the same error with vue3 and jest v.28, what solved it was to add我对 vue3 和 jest v.28 有同样的错误,解决它的方法是添加
testEnvironmentOptions: {
customExportConditions: ["node", "node-addons"],
},
into jest.config.js
.进入jest.config.js
。
You are using Vue version 2 with @vue/test-utils 2.0.0 which is for Vue version 3.您正在使用带有@vue/test-utils 2.0.0的 Vue 版本 2,它适用于 Vue 版本 3。
You can find the correct @vue/test-utils version for Vue 2 here您可以在此处找到适用于 Vue 2 的正确 @vue/test-utils 版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.