Skip to content

Conversation

@eranshabi
Copy link
Contributor

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

Copy link
Member

@SimenB SimenB left a 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!

@SimenB SimenB requested review from jeysal and thymikee July 18, 2019 13:35
Copy link
Collaborator

@jeysal jeysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid, thanks!

@deanshub
Copy link

@thymikee please please please?

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants