I am using ts-jest with ESM imports on nodejs.
The problem is that my jest.mock is not working, it is not mocking.
import { jest } from "@jest/globals";
jest.mock("./helpers"); // I tried before or after import
import { fn } from "./helpers";
describe("SimpleTest", () => {
it("should work", () => {
console.log(fn); // => defined
console.log(fn.mockReturnValue); // => /!\ UNDEFINED, fn is not a jest mock.
});
});
My jest config:
export default {
preset: "ts-jest/presets/default-esm",
extensionsToTreatAsEsm: [".ts"],
globals: {
"ts-jest": {
useESM: true,
},
},
}
The command I use:
node --experimental-vm-modules --experimental-specifier-resolution=node $(yarn bin jest)
I am using node v16.13.2 and ts-jest 27.1.3