-
-
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
add jest.advanceTimersToNextTimer method #8713
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, thank you so much for sending a PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks solid, thanks!
@thymikee please please please? |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
A contribution by me and @deanshub
Summary
When you test a code (using fake timers) with lots of timeouts/intervals, and some of the code is 3rd party, it's hard to keep track of the right amount of milliseconds you should advance timers by.
Moreover, sometimes you don't want to run all the timers, because you might want to
expect
something before the end of them all. (Maybe you need to assert between the second and third timeouts)jest.advanceTimersToNextTimer
will advance the timers by the correct milliseconds that make sense for the next assertion.The alternative is to run
jest.advanceTimersByTime(1)
a lot of times until you ran the right amount to make your test pass (runAllTimers
will run too much timers).We tried this new feature on our tests and they look much cleaner.
Test plan
Added tests to
jest-fake-timers