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
Fake timers behave unexpectedly with Promise.race()
.
#10258
Comments
I expect a bit from MDN's doc on
I'm not sure if I'm reading this right, but it might suggest that it's quite impossible for any fake-timer implementation that uses native Promises to behave comparably to when you use real timers. |
Running into similar issues with multiple timers and promises. Wouldn't it help to have an asynchronous version of By the looks of it, got to be a one-liner -- @sinonjs/faketimers runAllAsync() is already available but not used by Jest. Can either add jest._clock.runAllAsync() could be used as a kludge. |
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 14 days. |
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
馃悰 Bug Report
With
jest.useFakeTimers
(either 'modern' or 'legacy'), aPromise.race
between a short sleep Promise and a long sleep Promise...resolves to the long one's resolution, if the short one uses.then
.An identical
Promise.race
using real timers behaves as expected.To Reproduce
For example, with modern fake timers (but also observed with the legacy fake timers):
The second test, 'Promise.race with "then"', fails.
Expected behavior
I would expect the second test, 'Promise.race with "then"', to succeed; the shorter sleep should "win" the race, same as the version without "then". An identical test succeeds if you do
jest.useRealTimers()
.Link to repl or repo (highly encouraged)
Here, we have with-"then" and without-"then" tests for each of the following:
https://github.com/chrisbobbe/jest-modern-timers-race-then
envinfo
The text was updated successfully, but these errors were encountered: