From 6840e7eb0de034194c6ff02f0d1e6d976734b5af Mon Sep 17 00:00:00 2001 From: Lukas Tyla Date: Thu, 12 Sep 2024 17:49:18 +0300 Subject: [PATCH] [code-infra] Allow overriding all `options` of `useFakeTimers` function (#43729) --- packages-internal/test-utils/src/createRenderer.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages-internal/test-utils/src/createRenderer.tsx b/packages-internal/test-utils/src/createRenderer.tsx index 85889bc3d91..f7107db5c1a 100644 --- a/packages-internal/test-utils/src/createRenderer.tsx +++ b/packages-internal/test-utils/src/createRenderer.tsx @@ -371,7 +371,11 @@ export interface Clock { export type ClockConfig = undefined | number | Date; -function createClock(defaultMode: 'fake' | 'real', config: ClockConfig): Clock { +function createClock( + defaultMode: 'fake' | 'real', + config: ClockConfig, + options?: Exclude[0], number | Date>, +): Clock { let clock: ReturnType | null = null; let mode = defaultMode; @@ -384,6 +388,7 @@ function createClock(defaultMode: 'fake' | 'real', config: ClockConfig): Clock { // Technically we'd want to reset all modules between tests but we don't have that technology. // In the meantime just continue to clear native timers like with did for the past years when using `sinon` < 8. shouldClearNativeTimers: true, + ...options, }); } }); @@ -457,6 +462,7 @@ export interface CreateRendererOptions extends Pick[2]; } export function createRenderer(globalOptions: CreateRendererOptions = {}): Renderer { @@ -465,10 +471,11 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende clockConfig, strict: globalStrict = true, strictEffects: globalStrictEffects = globalStrict, + clockOptions, } = globalOptions; // save stack to re-use in test-hooks const { stack: createClientRenderStack } = new Error(); - const clock = createClock(clockMode, clockConfig); + const clock = createClock(clockMode, clockConfig, clockOptions); /** * Flag whether `createRenderer` was called in a suite i.e. describe() block.