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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
jest.useFakeTimers() does not work with whatwg-fetch>=3.1.0 #11103
Comments
You have to add |
runOnlyPendingTimers() didn't change anything. runAllTimers() caused infinite loop (due to other timers in my code). Is there some sort of debug thing for jest mock timers where I can see the current timers in flight? Based on the probing it seems like the whatwg-fetch addition of setTimeout is somehow not being mocked at all. |
The problem is the setTimeout isn't called until the promise is resolved...this must be BEFORE runOnlyPendingTimers is run, otherwise it doesn't advance that timer. However, since this is internal to whatwg-fetch library, I have no way of hooking code up to after the settimeout is called, since there is no promise resolution until that part runs. |
Call This way timers with setTimeout(fn,0) will be called and you promise will resolve. |
@CrOrc you already said that, and I tried to explain why that doesn't work. you can see this in my PR here reactive/data-client#553 Find any of the newly failing tests and add that - it doesn't work. I explained why in the comment above. |
I had hard time using |
This solved to mock frontend web API. |
I am experiencing the same issue, but it seems to work with the legacy If that is the case, perhaps the same special case could be introduced in the new implementation? |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
Still relevant. |
Any updates on this? Seems like devs are moving away from |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
馃悰 Bug Report
Due to this change: JakeChampion/fetch#575 using whatwg-fetch to make fetch work in node and then trying to run timers will cause the fetches to never resolve.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The promise should resolve. Instead, the nock response gets called - but the then clause of the promise never gets run
Link to repl or repo (highly encouraged)
reactive/data-client#553
envinfo
The text was updated successfully, but these errors were encountered: