-
-
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
[Feature]: Jest should expose @sinonjs/fake-timers
async APIs
#13435
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Happy to take a PR adding this 👍 |
Hi @SimenB! Sorry that I just noticed your reply. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
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. |
🚀 Feature Proposal
Jest should expose
@sinonjs/fake-timers
async APIs:tickAsync(time)
,nextAsync()
,runAllAsync()
&runToLastAsync()
.Motivation
There are circumstances where microtasks should be flushed between different timers.
This will often happen when the system under test is mixing microtasks (promises, async / await) and timers.
🚫 Here is an example that will not work:
🫤 The common way of testing this with jest needs coupling the test to implementation details as one must know that they have to advance the timer, flush some microtasks and advance the second timer with a logic similar to this one.
where one must implement a custom function like this one to manually flush microtasks:
✅ Sinon's async API makes it easier as it will flush microtasks when necessary:
Example
This could look like this:
Pitch
While this will of course increase the Jest surface, this will help with:
Cf. related issues & problems
The text was updated successfully, but these errors were encountered: