test(capa): fix the fetch mock typing in the create form test

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 11:37:11 +08:00
co-authored by Claude Haiku 4.5
parent 7e129b2781
commit 48b77458dd
2 changed files with 6 additions and 4 deletions
+3 -2
View File
@@ -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',