Skip to content

Commit f58eec6

Browse files
fix(test): type the fetch spy so tsc strict-tuple check passes
Vitest's vi.fn() with no signature returns Mock<[], unknown>; reading mock.calls[0][0] / [0][1] under TS strict (noUncheckedIndexedAccess + strict tuple types) raises TS2493. Give the spy a typed signature matching `fetch(input, init?)` so the destructuring works without casts. `npm run gate` clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a1cbe2f commit f58eec6

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

src/pages/LoginCallbackPage.test.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,24 @@ describe('LoginCallbackPage', () => {
8888
// ---- AUTH-004 (cookie-exchange) flow ----
8989

9090
it('AUTH-004: ?signed_in=1 → POSTs /auth/exchange with credentials:include + uses returned token', async () => {
91-
const fetchSpy = vi.fn(() => Promise.resolve(new Response(JSON.stringify({ token: 'xyz' }), {
92-
status: 200,
93-
headers: { 'Content-Type': 'application/json' },
94-
})))
91+
const fetchSpy = vi.fn(
92+
(_input: RequestInfo | URL, _init?: RequestInit) =>
93+
Promise.resolve(new Response(JSON.stringify({ token: 'xyz' }), {
94+
status: 200,
95+
headers: { 'Content-Type': 'application/json' },
96+
})),
97+
)
9598
;(globalThis as any).fetch = fetchSpy
9699
;(api.fetchMe as any).mockResolvedValue({ ok: true })
97100

98101
renderCallback('?signed_in=1')
99102
await waitFor(() => expect(screen.getByTestId('app-landed')).toBeTruthy())
100103

101104
expect(fetchSpy).toHaveBeenCalledTimes(1)
102-
const call = fetchSpy.mock.calls[0]
103-
expect(String(call[0])).toMatch(/\/auth\/exchange$/)
104-
expect((call[1] as RequestInit).method).toBe('POST')
105-
expect((call[1] as RequestInit).credentials).toBe('include')
105+
const [url, init] = fetchSpy.mock.calls[0] as [RequestInfo | URL, RequestInit]
106+
expect(String(url)).toMatch(/\/auth\/exchange$/)
107+
expect(init.method).toBe('POST')
108+
expect(init.credentials).toBe('include')
106109
expect(api.setToken).toHaveBeenCalledWith('xyz')
107110
})
108111

@@ -143,7 +146,9 @@ describe('LoginCallbackPage', () => {
143146

144147
it('AUTH-004: signed_in=1 + legacy session_token both present → legacy wins (idempotent fallback)', async () => {
145148
;(api.fetchMe as any).mockResolvedValue({ ok: true })
146-
const fetchSpy = vi.fn()
149+
const fetchSpy = vi.fn((_input: RequestInfo | URL, _init?: RequestInit) =>
150+
Promise.resolve(new Response('{}', { status: 200 })),
151+
)
147152
;(globalThis as any).fetch = fetchSpy
148153

149154
renderCallback('?signed_in=1&session_token=legacy123')

0 commit comments

Comments
 (0)