-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Bug]: Async function with multiple awaits never resolves when using fake timers #11876
Comments
This could be solvable if jest exposed the Until that happens, it can be solved by using fake-timers directly:
|
I have a similar situation to @nikopavlica, which i believe is the same issue.
My test code is as follows:
And the test fails with the following output:
No matter how much I advance the timers by, or event if I tell just to run all queued code with But replacing jest timers with the actual sinon timers solves the problem:
I now get the 3 console logs as expected and the test to pass. Furthermore, the proper correlation between the argument to |
I encountered this issue whilst writing tests this week. Unfortunately, I was unable to get it to work by switching to the
In short, it's a generic constructor function that wraps any function and retries it multiple times (full credit, modified from SO). The time to wait increases exponentially. Here's where things get weird though. In a test case where we have to delay some time, Jest's timer mocking works just fine. However, in tests where it should return null after several failed attempts, the test times out. I checked the maths and adjusted the number of attempts so it would fall well under the timer constraint but it still failed. I managed to fix this by changing
to
IE waiting a constant time each loop. I really don't understand why this happened, and it's frustrating to have to change implementation to address test concerns, but at least I got it to work. |
OP is fixed via #12572 by using |
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. |
Version
27.2.0
Steps to reproduce
yarn install
yarn test
Code:
Expected behavior
I expect all tests to pass. In the third test,
jest.runAllTimers
should cause both delays to complete, and the promise returned byf
should resolve.Actual behavior
The third test fails with
Additional context
The result is same when using
jest.useFakeTimers('legacy')
.Environment
The text was updated successfully, but these errors were encountered: