Skip to content

Commit

Permalink
fix: use setTimeout from globalThis
Browse files Browse the repository at this point in the history
  • Loading branch information
WillianAgostini committed Dec 24, 2023
1 parent db98814 commit 3707c1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions e2e/test-retries/__tests__/logErrorsBeforeRetries.test.js
Expand Up @@ -17,3 +17,18 @@ it('retryTimes set', () => {
expect(true).toBeFalsy();
}
});

let iFakeTimers = 0;
const startTimeInSecondsFakeTimers = new Date().getTime();
jest.retryTimes(3, {logErrorsBeforeRetry: true, waitBeforeRetry: 100});
it('retryTimes set with fake timers', () => {
jest.useFakeTimers();
iFakeTimers++;
if (iFakeTimers === 3) {
expect(new Date().getTime() - startTimeInSecondsFakeTimers).toBeGreaterThan(
200,
);
} else {
expect(true).toBeFalsy();
}
});
4 changes: 4 additions & 0 deletions packages/jest-circus/src/run.ts
Expand Up @@ -24,6 +24,10 @@ import {
makeRunResult,
} from './utils';

// Global values can be overwritten by mocks or tests. We'll capture
// the original values in the variables before we require any files.
const {setTimeout} = globalThis;

type ConcurrentTestEntry = Omit<Circus.TestEntry, 'fn'> & {
fn: Circus.ConcurrentTestFn;
};
Expand Down

0 comments on commit 3707c1a

Please sign in to comment.