出于某种原因,Jest没有拿起我的手动模拟实现。结构如下。我在这里错过了什么吗?肯定会挂起.mock电话,我已经用上面的模拟电话测试了它,但仍然没有骰子。
感谢任何帮助。
-
// "@/store/modules/__tests__/data"
import {fetchData} from "@/store/modules/data"
import {fetchByids} from "@/api/fetch";
jest.mock("@/api/fetch");
...
[ fetchByIds is considered the original still ? ]
-
// "@/store/modules/data"
import {fetchByIds} from "@/api/fetch";
...
export const fetchData = (context, payload) => {
fetchByIds(payload.id);
}
-
// "@/api/fetch"
export const fetchByIds = (id) => fetch(`url${id}`).then(response=>response.json())
-
// "@/api/__mocks__/fetch"
export const fetchByIds = jest.fn().mockImplementation(id => Promise.resolve({id}))
-
有趣的是,如果我将以下内容添加到"@/store/modules/__tests__/data"
,它会选择模拟实现。也许这可能是名称映射的问题?
jest.mock("@/api/fetch", () => ({
fetchByIds: jest.fn().mockImplementation(id => Promise.resolve({id}))
}));