从一个演示项目中,我可以看到:
src
components
ShoppingList.spec.js
ShoppingList.vue
store
__mocks__
index.js
index.js
ShoppingList.spec.js
import { __creareMocks as createMocks } from "../store";
...
jest.mock("../store");
此运行没有任何问题,两个导入都是正确的
========
我正在尝试使用它,但是在我自己的项目结构中
src
components
ContactForm.vue
store
index.js
tests
unit
store
__mocks__
index.js
ContactForm.spec.js
ContactForm.spec.js
import { __creareMocks as createMocks } from "../store";
...
jest.mock("../store");
两次导入均失败,并从“ ContactForm.spec.js”错误中找不到模块“ ../ store”
答案 0 :(得分:0)
正确的结构
src
components
ContactForm.vue
store
__mocks__
index.js
index.js
tests
unit
ContactForm.spec.js
ContactForm.spec.js
import { __creareMocks as createMocks } from "@/store";
...
jest.mock("@/store");