Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code-infra] Allow overriding all options of useFakeTimers function #43729

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages-internal/test-utils/src/createRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Parameters<typeof useFakeTimers>[0], number | Date>,
): Clock {
let clock: ReturnType<typeof useFakeTimers> | null = null;

let mode = defaultMode;
Expand All @@ -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,
});
}
});
Expand Down Expand Up @@ -457,6 +462,7 @@ export interface CreateRendererOptions extends Pick<RenderOptions, 'strict' | 's
*/
clock?: 'fake' | 'real';
clockConfig?: ClockConfig;
clockOptions?: Parameters<typeof createClock>[2];
}

export function createRenderer(globalOptions: CreateRendererOptions = {}): Renderer {
Expand All @@ -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.
Expand Down
Loading