Closed trivikr closed 1 year ago
This is a complex test case in Jest.
Adding wontfix
as of now.
This can be revisited in a new issue, if someone files a production use case in future.
Reopening, as I came across a test case which can be used for testing in workspace setup.
Input code:
jest.mock("./defaultExport", () => "defaultFromMock");
test("mockDefault", async () => {
const { default: defaultExport } = await import("./defaultExport");
expect(defaultExport).toBe("defaultFromMock");
});
Expected transform code:
import { expect, test, vi } from "vitest";
vi.mock("./defaultExport", () => ({ default: "defaultFromMock" }));
test("mockDefault", async () => {
const { default: defaultExport } = await import("./defaultExport");
expect(defaultExport).toBe("defaultFromMock");
});
Code being tested:
// defaultExport.js is a module that exports a default value.
module.exports = "default";
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Self-service
Problem
In vitest, the default exports need to be mocked as
default
Example test code:
Solution
The transformed code in vitest should be:
Alternatives
N/A
Additional context
No response