-
-
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
Jest with async function calls before and after setTimeout #10290
Comments
The following workaround works when func2() is synchronous:- In index.test.js, replace
with
But the above change gives the following output when func2 is async:-
|
Hi @sreetamdas I had already tried that before. The output hangs at the call of the Apparently, useFakeTimers breaks when used with native promises. It is a known issue in jest for almost 2 years now. |
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. |
This issue was closed because it has been stalled for 30 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
The scenario:- Using jest with nodejs, the function to be tested calls one
async function
, then calls asleep
function (wrapper over setTimeout to wait for a specific period of time), and then calls anotherfunction
(not necessarily async).While testing this with
jest.useFakeTimers()
andjest.advanceTimersByTime()/jest.runAllTimers()/jest.runOnlyPendingTimers()
, the first function and the sleep function gets called, but the code after the call to sleep function is not executed. The coverage report confirms that the lines after sleep function are not executed.The test passes.
Everything works as expected when func1 is synchronous.
How Can I make this work?
To Reproduce
Here is a basic example:-
index.js
index.test.js
Expected behavior
Test to pass with the following logging into console:-
Actual behaviour
Test passes with the following logging into console:-
Link to repl or repo (highly encouraged)
GitHub Repo for the above code
envinfo
The text was updated successfully, but these errors were encountered: