From de384fbeb757139faba276fdf74d583ec0f0b1b5 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 12 Sep 2024 10:51:10 +0300 Subject: [PATCH 1/4] [code-infra] Restore `clock` is restored when using `clock.withFakeTimers` --- packages-internal/test-utils/src/createRenderer.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages-internal/test-utils/src/createRenderer.tsx b/packages-internal/test-utils/src/createRenderer.tsx index 85889bc3d911a8..c92c5226c7e134 100644 --- a/packages-internal/test-utils/src/createRenderer.tsx +++ b/packages-internal/test-utils/src/createRenderer.tsx @@ -434,6 +434,7 @@ function createClock(defaultMode: 'fake' | 'real', config: ClockConfig): Clock { after(() => { mode = defaultMode; + this.restore(); }); }, restore() { From 7b172fb156a347067a346fa32cefaec2a6582417 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 12 Sep 2024 12:51:52 +0300 Subject: [PATCH 2/4] Test if block gets called --- packages-internal/test-utils/src/createRenderer.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages-internal/test-utils/src/createRenderer.tsx b/packages-internal/test-utils/src/createRenderer.tsx index c92c5226c7e134..91050597971deb 100644 --- a/packages-internal/test-utils/src/createRenderer.tsx +++ b/packages-internal/test-utils/src/createRenderer.tsx @@ -433,6 +433,7 @@ function createClock(defaultMode: 'fake' | 'real', config: ClockConfig): Clock { }); after(() => { + console.log('DEBUG: Called `withFakeTimers` "after" hook.'); mode = defaultMode; this.restore(); }); From 91ee9d15c3ef0a920748afb4d4c2383ae2fe34fc Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 12 Sep 2024 13:04:17 +0300 Subject: [PATCH 3/4] Try direct `clock.restore` call --- packages-internal/test-utils/src/createRenderer.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages-internal/test-utils/src/createRenderer.tsx b/packages-internal/test-utils/src/createRenderer.tsx index 91050597971deb..c1865e376bfb02 100644 --- a/packages-internal/test-utils/src/createRenderer.tsx +++ b/packages-internal/test-utils/src/createRenderer.tsx @@ -433,9 +433,8 @@ function createClock(defaultMode: 'fake' | 'real', config: ClockConfig): Clock { }); after(() => { - console.log('DEBUG: Called `withFakeTimers` "after" hook.'); mode = defaultMode; - this.restore(); + clock?.restore(); }); }, restore() { From 0358be124ce9b2e01021d3a33f0a6f1a8fc7c5d0 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 12 Sep 2024 18:05:23 +0300 Subject: [PATCH 4/4] Check `createClock` hooks --- packages-internal/test-utils/src/createRenderer.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages-internal/test-utils/src/createRenderer.tsx b/packages-internal/test-utils/src/createRenderer.tsx index c1865e376bfb02..8a4d020ec1de3b 100644 --- a/packages-internal/test-utils/src/createRenderer.tsx +++ b/packages-internal/test-utils/src/createRenderer.tsx @@ -378,6 +378,7 @@ function createClock(defaultMode: 'fake' | 'real', config: ClockConfig): Clock { beforeEach(() => { if (mode === 'fake') { + console.log('Initializing fake timers in `beforeEach` hook.'); clock = useFakeTimers({ now: config, // useIsFocusVisible schedules a global timer that needs to persist regardless of whether components are mounted or not. @@ -389,6 +390,7 @@ function createClock(defaultMode: 'fake' | 'real', config: ClockConfig): Clock { }); afterEach(() => { + console.log('Restoring fake timers in `afterEach` hook.'); clock?.restore(); clock = null; });