Skip to content

Commit 9d6fb4b

Browse files
authored
chore(docs): specify an error message in Timermocks (#12248)
1 parent 02506f8 commit 9d6fb4b

File tree

7 files changed

+50
-7
lines changed

7 files changed

+50
-7
lines changed

docs/TimerMocks.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ test('calls the callback after 1 second', () => {
7979

8080
## Run Pending Timers
8181

82-
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()`:
82+
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:
83+
84+
```
85+
Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...
86+
```
87+
88+
So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:
8389

8490
```javascript title="infiniteTimerGame.js"
8591
'use strict';

website/versioned_docs/version-25.x/TimerMocks.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ test('calls the callback after 1 second', () => {
6363

6464
## Run Pending Timers
6565

66-
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()`:
66+
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:
67+
68+
```
69+
Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...
70+
```
71+
72+
So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:
6773

6874
```javascript title="infiniteTimerGame.js"
6975
'use strict';

website/versioned_docs/version-26.x/TimerMocks.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ test('calls the callback after 1 second', () => {
6363

6464
## Run Pending Timers
6565

66-
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()`:
66+
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:
67+
68+
```
69+
Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...
70+
```
71+
72+
So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:
6773

6874
```javascript title="infiniteTimerGame.js"
6975
'use strict';

website/versioned_docs/version-27.0/TimerMocks.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ test('calls the callback after 1 second', () => {
8181

8282
## Run Pending Timers
8383

84-
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()`:
84+
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:
85+
86+
```
87+
Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...
88+
```
89+
90+
So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:
8591

8692
```javascript title="infiniteTimerGame.js"
8793
'use strict';

website/versioned_docs/version-27.1/TimerMocks.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ test('calls the callback after 1 second', () => {
8181

8282
## Run Pending Timers
8383

84-
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()`:
84+
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:
85+
86+
```
87+
Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...
88+
```
89+
90+
So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:
8591

8692
```javascript title="infiniteTimerGame.js"
8793
'use strict';

website/versioned_docs/version-27.2/TimerMocks.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ All of the following functions need fake timers to be set, either by `jest.useFa
6060
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:
6161

6262
```javascript
63+
jest.useFakeTimers();
6364
test('calls the callback after 1 second', () => {
6465
const timerGame = require('../timerGame');
6566
const callback = jest.fn();
@@ -80,7 +81,13 @@ test('calls the callback after 1 second', () => {
8081

8182
## Run Pending Timers
8283

83-
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()`:
84+
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:
85+
86+
```
87+
Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...
88+
```
89+
90+
So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:
8491

8592
```javascript title="infiniteTimerGame.js"
8693
'use strict';

website/versioned_docs/version-27.4/TimerMocks.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ test('calls the callback after 1 second', () => {
8181

8282
## Run Pending Timers
8383

84-
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()`:
84+
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:
85+
86+
```
87+
Ran 100000 timers, and there are still more! Assuming we've hit an infinite recursion and bailing out...
88+
```
89+
90+
So something like `jest.runAllTimers()` is not desirable. For these cases you might use `jest.runOnlyPendingTimers()`:
8591

8692
```javascript title="infiniteTimerGame.js"
8793
'use strict';

0 commit comments

Comments
 (0)