-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
MSW doesn't resolve with Jest 28 .useFakeTimers() #1390
Comments
Not sure, but this sounds related to to changes in Jest global injection, which will cause it to inject the node-native Here's a PR where I fixed a similar issue (see the first commit). You might find some helpful information in there. This PR is part of a series of PRs to add support for native The root problem is that msw does not intercept native |
Hi @milesrichardson, In the repro above this is also an issue on Node 16 and 14. Have updated the issue description. There is some discussion in #1388 around using |
Just adding my 2 cents. We encountered two kind of weird problems using the latest msw version (1.1 or something):
Both problems were fixed by downgrading to [email protected]. I found this working version by binary searching through msw versions. So it seems that from 0.42.0 onwards something changed with timers (or something..) My setup:
|
Any updates regarding this issue? |
Currently upgrading to v2, with Node 20.9, and now on Jest 29. The following config seems to work: const mockDate = new Date(2022, 6, 26);
beforeEach(() => {
jest.useFakeTimers({
now: mockDate,
doNotFake: ['queueMicrotask'],
});
});
afterEach(() => {
jest.useRealTimers();
}); |
I confirm that you should be |
Cheers @kettanaito - have to say upgrading our codebase from v1 -> v2 (~150 rest resolvers) was an absolute breeze, largely thanks to the fantastic new docs 🎉 |
Thank you, @harry-gocity! It means a lot to me to hear that! Writing the new docs took a ton of time. I'm happy to see that time paying off. |
Just commenting here as I'm currently on msw 0.x and this solution does not work for me. However if I add
Thanks @kettanaito for getting me 99% of the way there, hopefully this helps someone out who stumbles along this |
Prerequisites
Environment check
msw
versionNode.js version
14, 16, 18 (we are on 16)
Reproduction repository
https://github.com/harry-gocity/msw-examples/tree/repro
Reproduction steps
Switch to 'repro' branch
Run the tests in examples/with-jest
Test fails as MSW resolver does not respond
Current behavior
This has come up before (#448, #966, and elsewhere here and similarily here) but I can't find a solution when using
fetch
(polyfilled withwhatwg-fetch
and Jest 27 / 28. Please feel free to close this issue and direct me elsewhere if this isn't the case!I believe that this issue could be to do with jest mocking out functions used by MSW (
setTimeout
,nextTick
etc) but skipping these via Jest's selective faking has no effect.#1125 suggests it may be due to node version, but that's marked as solved.
Expected behavior
MSW resolver should respond
The text was updated successfully, but these errors were encountered: