esbuild-jest icon indicating copy to clipboard operation
esbuild-jest copied to clipboard

Mocking in jest doesn't work

Open yaronya opened this issue 3 years ago • 3 comments

I can't put a finger on the specific issue but what I experience is that my mocks gets stubbed (i.e return some default value as undefined) but doesn't treat .mockImplemenation or .mockRetrunValue at all.

I could see this issue https://github.com/aelbore/esbuild-jest/issues/12 but updating to latest hasn't fixed it for me 😿

yaronya avatar Jun 16 '21 08:06 yaronya

Same here - I tried both the latest and [email protected] builds. My jest mocks are not being mocked above my application code.

I'm using doMock specifically for context.

ShrayBans avatar Oct 23 '21 19:10 ShrayBans

When I changed the behavior to using mock, it was able to hoist the function and it actually worked!

However any helper functions that I want to pass in are not initialized and don't let me me check if they have been called.

i.e. expect(mockRetrieveBalance).toHaveBeenCalled();

Error: "Cannot access 'mockRetrieveBalance' before initialization"

ShrayBans avatar Oct 23 '21 19:10 ShrayBans

Any news on this issue ?

Med-H avatar Nov 14 '22 14:11 Med-H