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.
This commit is contained in:
@@ -58,11 +58,13 @@ function setLocation(url: string): void {
|
||||
describe("useDrawerUrlState", () => {
|
||||
// `vi.fn()` with no args in vitest 4 is typed `Mock<Procedure |
|
||||
// Constructable>`, 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<typeof vi.fn<() => void>>;
|
||||
let replaceStateMock: ReturnType<typeof vi.fn<() => 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<typeof vi.fn<PushState>>;
|
||||
let replaceStateMock: ReturnType<typeof vi.fn<PushState>>;
|
||||
|
||||
beforeEach(() => {
|
||||
pushStateMock = vi.fn();
|
||||
|
||||
Reference in New Issue
Block a user