-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jest.mock()
calls not getting hoisted to the top by esbuild-runner/jest
#40
Comments
+1 |
Can confirm, using // something.test.ts
import { importedFunction } from './otherFile'
jest.mock('./otherFile', () => ({
importedFunction: jest.fn().mockResolvedValue(true),
})) |
any solution for this? I replaced @swc/jest transformer with esbuild-runner/jest and jest.mock no longer works correctly some.test.ts import { myModule } from "@/someDir";
import { myFunction } from "@/myFunction";
jest.mock("@/someDir")
test("test1", () => {
(myModule as Jest.MockedFunction).mockImplementationOnce(() => Promise.resolve(true));
myFunction();
expect(myModule).toHaveBeenCalledTimes(1)
}); @/myFunction.ts import { myModule } from "@/someDir";
export function myFunction() {
// other code...
myModule();
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created an issue/question for this in SST at sst/sst#1065. I'm wondering if I'm doing something wrong or if this just a shortcoming of
esbuild-runner
. How come thejest.mock()
calls are not hoisted to the top in the generated JavaScript files of Jest tests written in TypeScript? Below is snippet of the resulting JavaScript, notice thejest.mock()
calls appear towards the middle, nowhere near the top as Jestbabel-jest
transformer for example would do,The text was updated successfully, but these errors were encountered: