Skip to content

Commit 077e850

Browse files
authored
docs: refactor jest.retryTimes() documentation (#13987)
1 parent 268afca commit 077e850

File tree

11 files changed

+298
-169
lines changed

11 files changed

+298
-169
lines changed

docs/JestObjectAPI.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,30 +1039,42 @@ Use the [`--showSeed`](CLI.md#--showseed) flag to print the seed in the test rep
10391039

10401040
Returns `true` if test environment has been torn down.
10411041

1042-
### `jest.retryTimes(numRetries, options)`
1042+
### `jest.retryTimes(numRetries, options?)`
10431043

1044-
Runs failed tests n-times until they pass or until the max number of retries is exhausted. `options` are optional. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner! This must live at the top-level of a test file or in a describe block. Retries _will not_ work if `jest.retryTimes()` is called in a `beforeEach` or a `test` block.
1045-
1046-
Example in a test:
1044+
Runs failed tests n-times until they pass or until the max number of retries is exhausted.
10471045

10481046
```js
10491047
jest.retryTimes(3);
1048+
10501049
test('will fail', () => {
10511050
expect(true).toBe(false);
10521051
});
10531052
```
10541053

1055-
If `logErrorsBeforeRetry` is enabled, Jest will log the error(s) that caused the test to fail to the console, providing visibility on why a retry occurred.
1054+
If `logErrorsBeforeRetry` option is enabled, error(s) that caused the test to fail will be logged to the console.
10561055

10571056
```js
10581057
jest.retryTimes(3, {logErrorsBeforeRetry: true});
1058+
10591059
test('will fail', () => {
10601060
expect(true).toBe(false);
10611061
});
10621062
```
10631063

10641064
Returns the `jest` object for chaining.
10651065

1066+
:::caution
1067+
1068+
`jest.retryTimes()` must be declared at the top level of a test file or in a `describe` block.
1069+
1070+
:::
1071+
1072+
:::info
1073+
1074+
This function is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.
1075+
1076+
:::
1077+
10661078
### `jest.setTimeout(timeout)`
10671079

10681080
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called. The default timeout interval is 5 seconds if this method is not called.

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,32 @@ Returns the number of fake timers still left to run.
660660

661661
## Misc
662662

663+
### `jest.retryTimes(numRetries, options?)`
664+
665+
Runs failed tests n-times until they pass or until the max number of retries is exhausted.
666+
667+
```js
668+
jest.retryTimes(3);
669+
670+
test('will fail', () => {
671+
expect(true).toBe(false);
672+
});
673+
```
674+
675+
Returns the `jest` object for chaining.
676+
677+
:::caution
678+
679+
`jest.retryTimes()` must be declared at the top level of a test file or in a `describe` block.
680+
681+
:::
682+
683+
:::info
684+
685+
This function is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.
686+
687+
:::
688+
663689
### `jest.setTimeout(timeout)`
664690

665691
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called.
@@ -675,18 +701,3 @@ Example:
675701
```js
676702
jest.setTimeout(1000); // 1 second
677703
```
678-
679-
### `jest.retryTimes()`
680-
681-
Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus)!
682-
683-
Example in a test:
684-
685-
```js
686-
jest.retryTimes(3);
687-
test('will fail', () => {
688-
expect(true).toBe(false);
689-
});
690-
```
691-
692-
Returns the `jest` object for chaining.

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,32 @@ When mocking time, `Date.now()` will also be mocked. If you for some reason need
680680
681681
## Misc
682682

683+
### `jest.retryTimes(numRetries, options?)`
684+
685+
Runs failed tests n-times until they pass or until the max number of retries is exhausted.
686+
687+
```js
688+
jest.retryTimes(3);
689+
690+
test('will fail', () => {
691+
expect(true).toBe(false);
692+
});
693+
```
694+
695+
Returns the `jest` object for chaining.
696+
697+
:::caution
698+
699+
`jest.retryTimes()` must be declared at the top level of a test file or in a `describe` block.
700+
701+
:::
702+
703+
:::info
704+
705+
This function is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.
706+
707+
:::
708+
683709
### `jest.setTimeout(timeout)`
684710

685711
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called.
@@ -695,18 +721,3 @@ Example:
695721
```js
696722
jest.setTimeout(1000); // 1 second
697723
```
698-
699-
### `jest.retryTimes()`
700-
701-
Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus)!
702-
703-
Example in a test:
704-
705-
```js
706-
jest.retryTimes(3);
707-
test('will fail', () => {
708-
expect(true).toBe(false);
709-
});
710-
```
711-
712-
Returns the `jest` object for chaining.

website/versioned_docs/version-27.x/JestObjectAPI.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,32 @@ When mocking time, `Date.now()` will also be mocked. If you for some reason need
720720
721721
## Misc
722722

723+
### `jest.retryTimes(numRetries, options?)`
724+
725+
Runs failed tests n-times until they pass or until the max number of retries is exhausted.
726+
727+
```js
728+
jest.retryTimes(3);
729+
730+
test('will fail', () => {
731+
expect(true).toBe(false);
732+
});
733+
```
734+
735+
Returns the `jest` object for chaining.
736+
737+
:::caution
738+
739+
`jest.retryTimes()` must be declared at the top level of a test file or in a `describe` block.
740+
741+
:::
742+
743+
:::info
744+
745+
This function is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.
746+
747+
:::
748+
723749
### `jest.setTimeout(timeout)`
724750

725751
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called.
@@ -735,18 +761,3 @@ Example:
735761
```js
736762
jest.setTimeout(1000); // 1 second
737763
```
738-
739-
### `jest.retryTimes()`
740-
741-
Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner! This must live at the top-level of a test file or in a describe block. Retries _will not_ work if `jest.retryTimes()` is called in a `beforeEach` or a `test` block.
742-
743-
Example in a test:
744-
745-
```js
746-
jest.retryTimes(3);
747-
test('will fail', () => {
748-
expect(true).toBe(false);
749-
});
750-
```
751-
752-
Returns the `jest` object for chaining.

website/versioned_docs/version-28.x/JestObjectAPI.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -837,42 +837,54 @@ This function is not available when using legacy fake timers implementation.
837837

838838
## Misc
839839

840-
### `jest.setTimeout(timeout)`
841-
842-
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called.
843-
844-
To set timeout intervals on different tests in the same file, use the [`timeout` option on each individual test](GlobalAPI.md#testname-fn-timeout).
845-
846-
_Note: The default timeout interval is 5 seconds if this method is not called._
847-
848-
_Note: If you want to set the timeout for all test files, a good place to do this is in `setupFilesAfterEnv`._
840+
### `jest.retryTimes(numRetries, options?)`
849841

850-
Example:
851-
852-
```js
853-
jest.setTimeout(1000); // 1 second
854-
```
855-
856-
### `jest.retryTimes(numRetries, options)`
857-
858-
Runs failed tests n-times until they pass or until the max number of retries is exhausted. `options` are optional. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner! This must live at the top-level of a test file or in a describe block. Retries _will not_ work if `jest.retryTimes()` is called in a `beforeEach` or a `test` block.
859-
860-
Example in a test:
842+
Runs failed tests n-times until they pass or until the max number of retries is exhausted.
861843

862844
```js
863845
jest.retryTimes(3);
846+
864847
test('will fail', () => {
865848
expect(true).toBe(false);
866849
});
867850
```
868851

869-
If `logErrorsBeforeRetry` is enabled, Jest will log the error(s) that caused the test to fail to the console, providing visibility on why a retry occurred.
852+
If `logErrorsBeforeRetry` option is enabled, error(s) that caused the test to fail will be logged to the console.
870853

871854
```js
872855
jest.retryTimes(3, {logErrorsBeforeRetry: true});
856+
873857
test('will fail', () => {
874858
expect(true).toBe(false);
875859
});
876860
```
877861

878862
Returns the `jest` object for chaining.
863+
864+
:::caution
865+
866+
`jest.retryTimes()` must be declared at the top level of a test file or in a `describe` block.
867+
868+
:::
869+
870+
:::info
871+
872+
This function is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.
873+
874+
:::
875+
876+
### `jest.setTimeout(timeout)`
877+
878+
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called.
879+
880+
To set timeout intervals on different tests in the same file, use the [`timeout` option on each individual test](GlobalAPI.md#testname-fn-timeout).
881+
882+
_Note: The default timeout interval is 5 seconds if this method is not called._
883+
884+
_Note: If you want to set the timeout for all test files, a good place to do this is in `setupFilesAfterEnv`._
885+
886+
Example:
887+
888+
```js
889+
jest.setTimeout(1000); // 1 second
890+
```

website/versioned_docs/version-29.0/JestObjectAPI.md

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -837,44 +837,56 @@ This function is not available when using legacy fake timers implementation.
837837

838838
## Misc
839839

840-
### `jest.setTimeout(timeout)`
840+
### `jest.retryTimes(numRetries, options?)`
841841

842-
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called. The default timeout interval is 5 seconds if this method is not called.
842+
Runs failed tests n-times until they pass or until the max number of retries is exhausted.
843843

844-
Example:
844+
```js
845+
jest.retryTimes(3);
846+
847+
test('will fail', () => {
848+
expect(true).toBe(false);
849+
});
850+
```
851+
852+
If `logErrorsBeforeRetry` option is enabled, error(s) that caused the test to fail will be logged to the console.
845853

846854
```js
847-
jest.setTimeout(1000); // 1 second
855+
jest.retryTimes(3, {logErrorsBeforeRetry: true});
856+
857+
test('will fail', () => {
858+
expect(true).toBe(false);
859+
});
848860
```
849861

850-
:::tip
862+
Returns the `jest` object for chaining.
851863

852-
To set timeout intervals on different tests in the same file, use the [`timeout` option on each individual test](GlobalAPI.md#testname-fn-timeout).
864+
:::caution
853865

854-
If you want to set the timeout for all test files, use [`testTimeout`](Configuration.md#testtimeout-number) configuration option.
866+
`jest.retryTimes()` must be declared at the top level of a test file or in a `describe` block.
855867

856868
:::
857869

858-
### `jest.retryTimes(numRetries, options)`
870+
:::info
859871

860-
Runs failed tests n-times until they pass or until the max number of retries is exhausted. `options` are optional. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner! This must live at the top-level of a test file or in a describe block. Retries _will not_ work if `jest.retryTimes()` is called in a `beforeEach` or a `test` block.
872+
This function is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.
861873

862-
Example in a test:
874+
:::
863875

864-
```js
865-
jest.retryTimes(3);
866-
test('will fail', () => {
867-
expect(true).toBe(false);
868-
});
869-
```
876+
### `jest.setTimeout(timeout)`
877+
878+
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called. The default timeout interval is 5 seconds if this method is not called.
870879

871-
If `logErrorsBeforeRetry` is enabled, Jest will log the error(s) that caused the test to fail to the console, providing visibility on why a retry occurred.
880+
Example:
872881

873882
```js
874-
jest.retryTimes(3, {logErrorsBeforeRetry: true});
875-
test('will fail', () => {
876-
expect(true).toBe(false);
877-
});
883+
jest.setTimeout(1000); // 1 second
878884
```
879885

880-
Returns the `jest` object for chaining.
886+
:::tip
887+
888+
To set timeout intervals on different tests in the same file, use the [`timeout` option on each individual test](GlobalAPI.md#testname-fn-timeout).
889+
890+
If you want to set the timeout for all test files, use [`testTimeout`](Configuration.md#testtimeout-number) configuration option.
891+
892+
:::

0 commit comments

Comments
 (0)