Skip to content
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 helpful error message to TimerMocks #10184

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/TimerMocks.md
Expand Up @@ -62,7 +62,15 @@ test('calls the callback after 1 second', () => {

## Run Pending Timers

There are also scenarios where you might have a recursive timer -- that is a timer that sets a new timer in its own callback. For these, running all the timers would be an endless loop… so something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:
There are also scenarios where you might have a recursive timer -- that is a timer that sets a new timer in its own callback.

For these, running all the timers would be an endless loop, throwing the following error:

```Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...```
Copy link
Member

@SimenB SimenB Jun 23, 2020

Choose a reason for hiding this comment

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

could you run prettier on this file?


So something like `jest.runAllTimers()` is not desirable.

For these cases you might use `jest.runOnlyPendingTimers()`:

```javascript
// infiniteTimerGame.js
Expand Down