Skip to content

Commit

Permalink
chore(docs): specify an error message in Timermocks (#12248)
Browse files Browse the repository at this point in the history
  • Loading branch information
Biki-das committed Feb 5, 2022
1 parent 02506f8 commit 9d6fb4b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 7 deletions.
8 changes: 7 additions & 1 deletion docs/TimerMocks.md
Expand Up @@ -79,7 +79,13 @@ 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...
```

So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:

```javascript title="infiniteTimerGame.js"
'use strict';
Expand Down
8 changes: 7 additions & 1 deletion website/versioned_docs/version-25.x/TimerMocks.md
Expand Up @@ -63,7 +63,13 @@ 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...
```

So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:

```javascript title="infiniteTimerGame.js"
'use strict';
Expand Down
8 changes: 7 additions & 1 deletion website/versioned_docs/version-26.x/TimerMocks.md
Expand Up @@ -63,7 +63,13 @@ 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...
```

So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:

```javascript title="infiniteTimerGame.js"
'use strict';
Expand Down
8 changes: 7 additions & 1 deletion website/versioned_docs/version-27.0/TimerMocks.md
Expand Up @@ -81,7 +81,13 @@ 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...
```

So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:

```javascript title="infiniteTimerGame.js"
'use strict';
Expand Down
8 changes: 7 additions & 1 deletion website/versioned_docs/version-27.1/TimerMocks.md
Expand Up @@ -81,7 +81,13 @@ 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...
```

So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:

```javascript title="infiniteTimerGame.js"
'use strict';
Expand Down
9 changes: 8 additions & 1 deletion website/versioned_docs/version-27.2/TimerMocks.md
Expand Up @@ -60,6 +60,7 @@ All of the following functions need fake timers to be set, either by `jest.useFa
Another test we might want to write for this module is one that asserts that the callback is called after 1 second. To do this, we're going to use Jest's timer control APIs to fast-forward time right in the middle of the test:

```javascript
jest.useFakeTimers();
test('calls the callback after 1 second', () => {
const timerGame = require('../timerGame');
const callback = jest.fn();
Expand All @@ -80,7 +81,13 @@ 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...
```

So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:

```javascript title="infiniteTimerGame.js"
'use strict';
Expand Down
8 changes: 7 additions & 1 deletion website/versioned_docs/version-27.4/TimerMocks.md
Expand Up @@ -81,7 +81,13 @@ 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...
```

So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:

```javascript title="infiniteTimerGame.js"
'use strict';
Expand Down

0 comments on commit 9d6fb4b

Please sign in to comment.