From ecb31a71f03e6ba191c96988e1e88379bacfb241 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Mon, 19 Oct 2020 07:12:07 -0400 Subject: [PATCH] refactor(fake-timers): don't setup fakeTimerAPIs unless needed (#10551) --- CHANGELOG.md | 1 + packages/jest-fake-timers/src/legacyFakeTimers.ts | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59327bcc66b9..af509dc47089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes +- `[jest-fake-timers]` Lazily instantiate mock timers ([#10551](https://github.com/facebook/jest/pull/10551)) - `[jest-runtime]` `require.main` is no longer `undefined` when using `jest.resetModules` ([#10626](https://github.com/facebook/jest/pull/10626)) - `[@jest/types]` Add missing values for `timers` ([#10632](https://github.com/facebook/jest/pull/10632)) diff --git a/packages/jest-fake-timers/src/legacyFakeTimers.ts b/packages/jest-fake-timers/src/legacyFakeTimers.ts index 66be88c2518f..cb7a2abab30c 100644 --- a/packages/jest-fake-timers/src/legacyFakeTimers.ts +++ b/packages/jest-fake-timers/src/legacyFakeTimers.ts @@ -94,7 +94,6 @@ export default class FakeTimers { }; this.reset(); - this._createMocks(); } clearAllTimers(): void { @@ -349,7 +348,7 @@ export default class FakeTimers { } private _checkFakeTimers() { - if (this._global.setTimeout !== this._fakeTimerAPIs.setTimeout) { + if (this._global.setTimeout !== this._fakeTimerAPIs?.setTimeout) { this._global.console.warn( `A function to advance timers was called but the timers API is not ` + `mocked with fake timers. Call \`jest.useFakeTimers()\` in this ` +