From 24d13faca71cc8890fc4c5719022959c55d9adc9 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 20 Jun 2026 10:54:29 -0600 Subject: [PATCH] fix(frontend): type pushState mocks with real History.pushState signature - npm run typecheck failed on the 0-arg vi.fn<() => void>() because mock.calls[0] became an empty tuple, so calls[0][2] (the URL arg) was typed as undefined. - Constrain the mock to the real (state, unused, url?) signature so mock.calls[0] is a 3-tuple and [2] is string-or-URL-or-null. Drops the as-string cast at every callsite. --- src/hooks/useDrawerUrlState.test.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hooks/useDrawerUrlState.test.ts b/src/hooks/useDrawerUrlState.test.ts index 9819bb7..3185534 100644 --- a/src/hooks/useDrawerUrlState.test.ts +++ b/src/hooks/useDrawerUrlState.test.ts @@ -58,11 +58,13 @@ function setLocation(url: string): void { describe("useDrawerUrlState", () => { // `vi.fn()` with no args in vitest 4 is typed `Mock`, which carries a constructor signature and won't - // assign to `() => void`. Constraining the generic to `vi.fn<() => void>()` - // gives a plain function-typed mock that flows directly into `pushState` - // / `replaceState` slots. - let pushStateMock: ReturnType void>>; - let replaceStateMock: ReturnType void>>; + // assign to a real `pushState` slot. Constrain the generic to the + // `History.pushState` signature so the mock flows into `vi.stubGlobal` + // without complaint AND `mock.calls[0]` is typed as a 3-tuple, letting + // us read `calls[0][2]` (the URL) without an `as unknown` cast. + type PushState = (state: unknown, unused: string, url?: string | URL | null) => void; + let pushStateMock: ReturnType>; + let replaceStateMock: ReturnType>; beforeEach(() => { pushStateMock = vi.fn();