From 607f79b77200974589713764d69dae4c846c72d5 Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Wed, 23 Sep 2020 15:16:46 -0400 Subject: [PATCH 1/3] refactor(fake-timers): don't setup _fakeTimerAPIs unless needed --- packages/jest-fake-timers/src/legacyFakeTimers.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/jest-fake-timers/src/legacyFakeTimers.ts b/packages/jest-fake-timers/src/legacyFakeTimers.ts index 1f865bcb0cf7..8147c788c291 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 ` + From abcdd3ebb44df3ddb0586473266dc225a90c6f78 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 19 Oct 2020 12:33:24 +0200 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99689b1d4169..6ec5da0c568f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - `[jest-circus, jest-jasmine2]` Find correct location for `test.each` tests ([#10413](https://github.com/facebook/jest/pull/10413)) - `[jest-console]` Add `Console` constructor to `console` object ([#10502](https://github.com/facebook/jest/pull/10502)) +- `[jest-fake-timers]` Lazily instantiate mock timers ([#10551](https://github.com/facebook/jest/pull/10551)) - `[jest-globals]` Fix lifecycle hook function types ([#10480](https://github.com/facebook/jest/pull/10480)) ### Chore & Maintenance From a198556e0ed0186302cee22b51ca27547a606b27 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 19 Oct 2020 12:34:58 +0200 Subject: [PATCH 3/3] move changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3663e78adc3e..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)) @@ -59,7 +60,6 @@ - `[jest-circus, jest-jasmine2]` Find correct location for `test.each` tests ([#10413](https://github.com/facebook/jest/pull/10413)) - `[jest-console]` Add `Console` constructor to `console` object ([#10502](https://github.com/facebook/jest/pull/10502)) -- `[jest-fake-timers]` Lazily instantiate mock timers ([#10551](https://github.com/facebook/jest/pull/10551)) - `[jest-globals]` Fix lifecycle hook function types ([#10480](https://github.com/facebook/jest/pull/10480)) - `[jest-runtime]` Remove usage of `vm.compileFunction` due to a performance issue ([#10586](https://github.com/facebook/jest/pull/10586))