From 9d6fb4b1fa8f2399b7296bce06e5f3e5a662f675 Mon Sep 17 00:00:00 2001 From: BIKI DAS Date: Sat, 5 Feb 2022 13:35:34 +0530 Subject: [PATCH] chore(docs): specify an error message in Timermocks (#12248) --- docs/TimerMocks.md | 8 +++++++- website/versioned_docs/version-25.x/TimerMocks.md | 8 +++++++- website/versioned_docs/version-26.x/TimerMocks.md | 8 +++++++- website/versioned_docs/version-27.0/TimerMocks.md | 8 +++++++- website/versioned_docs/version-27.1/TimerMocks.md | 8 +++++++- website/versioned_docs/version-27.2/TimerMocks.md | 9 ++++++++- website/versioned_docs/version-27.4/TimerMocks.md | 8 +++++++- 7 files changed, 50 insertions(+), 7 deletions(-) diff --git a/docs/TimerMocks.md b/docs/TimerMocks.md index 105a5b6285c1..29613b26dbff 100644 --- a/docs/TimerMocks.md +++ b/docs/TimerMocks.md @@ -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'; diff --git a/website/versioned_docs/version-25.x/TimerMocks.md b/website/versioned_docs/version-25.x/TimerMocks.md index 5731c8cd585f..8598c63c7e6c 100644 --- a/website/versioned_docs/version-25.x/TimerMocks.md +++ b/website/versioned_docs/version-25.x/TimerMocks.md @@ -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'; diff --git a/website/versioned_docs/version-26.x/TimerMocks.md b/website/versioned_docs/version-26.x/TimerMocks.md index 5731c8cd585f..8598c63c7e6c 100644 --- a/website/versioned_docs/version-26.x/TimerMocks.md +++ b/website/versioned_docs/version-26.x/TimerMocks.md @@ -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'; diff --git a/website/versioned_docs/version-27.0/TimerMocks.md b/website/versioned_docs/version-27.0/TimerMocks.md index 037e16cab377..44c210c4eebe 100644 --- a/website/versioned_docs/version-27.0/TimerMocks.md +++ b/website/versioned_docs/version-27.0/TimerMocks.md @@ -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'; diff --git a/website/versioned_docs/version-27.1/TimerMocks.md b/website/versioned_docs/version-27.1/TimerMocks.md index 037e16cab377..44c210c4eebe 100644 --- a/website/versioned_docs/version-27.1/TimerMocks.md +++ b/website/versioned_docs/version-27.1/TimerMocks.md @@ -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'; diff --git a/website/versioned_docs/version-27.2/TimerMocks.md b/website/versioned_docs/version-27.2/TimerMocks.md index 88266c429cbd..44c210c4eebe 100644 --- a/website/versioned_docs/version-27.2/TimerMocks.md +++ b/website/versioned_docs/version-27.2/TimerMocks.md @@ -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(); @@ -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'; diff --git a/website/versioned_docs/version-27.4/TimerMocks.md b/website/versioned_docs/version-27.4/TimerMocks.md index 037e16cab377..44c210c4eebe 100644 --- a/website/versioned_docs/version-27.4/TimerMocks.md +++ b/website/versioned_docs/version-27.4/TimerMocks.md @@ -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';