-
Hi, I run into a problem in migrating to vitest from jest. I have to mock an external API module but this module also includes Error classes. In order properly be able to use jest.mock("api", () => {
const { ResponseError } = jest.requireActual<typeof import("api")>("api");
const mocks = jest.createMockFromModule<typeof import("api")>("api");
return { ...mocks, ResponseError };
}); A similar approach in vitest does not work for me and nothing gets mocked. vi.mock(import("api"), async (importOriginal) => {
const { ResponseError } = await importOriginal();
const mocks = await vi.importMock("api");
return { ...mocks, ResponseError };
}); I can't find a solution but making a fake module only for the error class and I just tried to avoid it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Beta Was this translation helpful? Give feedback.
-
Ok thanks for the answer. I wasn't able to find anything or how to word my problem accordingly 😅✌️ |
Beta Was this translation helpful? Give feedback.
createMockFromModule
is not supported yet andvi.importMock
is not a same thing. We still have an issue for that #5482