diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index e231ad590f87..7ab2b55efa45 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -1139,7 +1139,7 @@ test('will fail', () => { }); ``` -`immediately` option is used to retry the failed test immediately. +`immediately` option is used to retry the failed test immediately after the failure. If this option is not specified, the tests are retried after Jest is finished running all test in a file. ```js jest.retryTimes(3, {immediately: true}); diff --git a/packages/jest-circus/src/run.ts b/packages/jest-circus/src/run.ts index dec3af02d943..0081a64453f1 100644 --- a/packages/jest-circus/src/run.ts +++ b/packages/jest-circus/src/run.ts @@ -78,6 +78,7 @@ const _runTestsForDescribeBlock = async ( (global as Global.Global)[WAIT_BEFORE_RETRY] as string, 10, ) || 0; + const retryImmediately: boolean = // eslint-disable-next-line no-restricted-globals ((global as Global.Global)[IMMEDIATELY] as any) || false; diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index f3b2e648cec1..37c61495d1a4 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -309,9 +309,9 @@ export interface Jest { retryTimes( numRetries: number, options?: { + immediately?: boolean; logErrorsBeforeRetry?: boolean; waitBeforeRetry?: number; - immediately?: boolean; }, ): Jest; /** diff --git a/packages/jest-types/__typetests__/jest.test.ts b/packages/jest-types/__typetests__/jest.test.ts index bdd26ae82811..9c5530e1e3eb 100644 --- a/packages/jest-types/__typetests__/jest.test.ts +++ b/packages/jest-types/__typetests__/jest.test.ts @@ -667,6 +667,9 @@ expect(jest.retryTimes(3, {logErrorsBeforeRetry: 'all'})).type.toRaiseError(); expect(jest.retryTimes({logErrorsBeforeRetry: true})).type.toRaiseError(); expect(jest.retryTimes(3, {waitBeforeRetry: 1000})).type.toEqual(); expect(jest.retryTimes(3, {waitBeforeRetry: true})).type.toRaiseError(); +expect(jest.retryTimes(3, {immediately: true})).type.toEqual(); +expect(jest.retryTimes(3, {immediately: 'now'})).type.toRaiseError(); +expect(jest.retryTimes(3, {immediately: 1000})).type.toRaiseError(); expect(jest.retryTimes({logErrorsBeforeRetry: 'all'})).type.toRaiseError(); expect(jest.retryTimes()).type.toRaiseError();