From fd78e726691706fea3f68bfe3a61ab2f208ed8d6 Mon Sep 17 00:00:00 2001 From: weeihan Date: Thu, 1 Oct 2026 11:37:11 +0800 Subject: [PATCH] test(capa): fix the fetch mock typing in the create form test Co-Authored-By: Claude Haiku 4.5 --- .../plans/2026-10-01-ims-admin-refresh-slice-2-capa.md | 5 +++-- tests/components/capa/capa-form.test.tsx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/superpowers/plans/2026-10-01-ims-admin-refresh-slice-2-capa.md b/docs/superpowers/plans/2026-10-01-ims-admin-refresh-slice-2-capa.md index 7bb3f18..84b2485 100644 --- a/docs/superpowers/plans/2026-10-01-ims-admin-refresh-slice-2-capa.md +++ b/docs/superpowers/plans/2026-10-01-ims-admin-refresh-slice-2-capa.md @@ -1434,7 +1434,8 @@ import { CapaForm } from '@/components/capa/capa-form' const users = [{ id: 'u1', name: 'Tan Mei Ling', department: 'Facilities' }] function stubFetch(postResponse: { ok: boolean; body?: unknown } = { ok: true }) { - const fn = vi.fn(async (url: string) => { + const fn = vi.fn(async (url: string, init?: RequestInit) => { + void init if (url === '/api/users') return { ok: true, json: async () => users } return { ok: postResponse.ok, json: async () => postResponse.body ?? {} } }) @@ -1478,7 +1479,7 @@ describe('CapaForm', () => { fireEvent.change(screen.getByLabelText('Priority'), { target: { value: 'high' } }) fireEvent.submit(container.querySelector('form')!) await waitFor(() => expect(push).toHaveBeenCalledWith('/hse/incidents/inc1')) - expect(JSON.parse(postCall(fn)![1].body as string)).toEqual({ + expect(JSON.parse(postCall(fn)![1]!.body as string)).toEqual({ incident_id: 'inc1', description: 'Re-coat the ramp', owner_user_id: 'u1', diff --git a/tests/components/capa/capa-form.test.tsx b/tests/components/capa/capa-form.test.tsx index 295f2ec..1dd9a29 100644 --- a/tests/components/capa/capa-form.test.tsx +++ b/tests/components/capa/capa-form.test.tsx @@ -10,7 +10,8 @@ import { CapaForm } from '@/components/capa/capa-form' const users = [{ id: 'u1', name: 'Tan Mei Ling', department: 'Facilities' }] function stubFetch(postResponse: { ok: boolean; body?: unknown } = { ok: true }) { - const fn = vi.fn(async (url: string) => { + const fn = vi.fn(async (url: string, init?: RequestInit) => { + void init if (url === '/api/users') return { ok: true, json: async () => users } return { ok: postResponse.ok, json: async () => postResponse.body ?? {} } }) @@ -54,7 +55,7 @@ describe('CapaForm', () => { fireEvent.change(screen.getByLabelText('Priority'), { target: { value: 'high' } }) fireEvent.submit(container.querySelector('form')!) await waitFor(() => expect(push).toHaveBeenCalledWith('/hse/incidents/inc1')) - expect(JSON.parse(postCall(fn)![1].body as string)).toEqual({ + expect(JSON.parse(postCall(fn)![1]!.body as string)).toEqual({ incident_id: 'inc1', description: 'Re-coat the ramp', owner_user_id: 'u1',