Skip to content

Commit ecb31a7

Browse files
authored
refactor(fake-timers): don't setup fakeTimerAPIs unless needed (#10551)
1 parent 621ecf7 commit ecb31a7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Fixes
88

9+
- `[jest-fake-timers]` Lazily instantiate mock timers ([#10551](https://github.com/facebook/jest/pull/10551))
910
- `[jest-runtime]` `require.main` is no longer `undefined` when using `jest.resetModules` ([#10626](https://github.com/facebook/jest/pull/10626))
1011
- `[@jest/types]` Add missing values for `timers` ([#10632](https://github.com/facebook/jest/pull/10632))
1112

packages/jest-fake-timers/src/legacyFakeTimers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export default class FakeTimers<TimerRef> {
9494
};
9595

9696
this.reset();
97-
this._createMocks();
9897
}
9998

10099
clearAllTimers(): void {
@@ -349,7 +348,7 @@ export default class FakeTimers<TimerRef> {
349348
}
350349

351350
private _checkFakeTimers() {
352-
if (this._global.setTimeout !== this._fakeTimerAPIs.setTimeout) {
351+
if (this._global.setTimeout !== this._fakeTimerAPIs?.setTimeout) {
353352
this._global.console.warn(
354353
`A function to advance timers was called but the timers API is not ` +
355354
`mocked with fake timers. Call \`jest.useFakeTimers()\` in this ` +

0 commit comments

Comments
 (0)