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:
@@ -1434,7 +1434,8 @@ import { CapaForm } from '@/components/capa/capa-form'
|
|||||||
const users = [{ id: 'u1', name: 'Tan Mei Ling', department: 'Facilities' }]
|
const users = [{ id: 'u1', name: 'Tan Mei Ling', department: 'Facilities' }]
|
||||||
|
|
||||||
function stubFetch(postResponse: { ok: boolean; body?: unknown } = { ok: true }) {
|
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 }
|
if (url === '/api/users') return { ok: true, json: async () => users }
|
||||||
return { ok: postResponse.ok, json: async () => postResponse.body ?? {} }
|
return { ok: postResponse.ok, json: async () => postResponse.body ?? {} }
|
||||||
})
|
})
|
||||||
@@ -1478,7 +1479,7 @@ describe('CapaForm', () => {
|
|||||||
fireEvent.change(screen.getByLabelText('Priority'), { target: { value: 'high' } })
|
fireEvent.change(screen.getByLabelText('Priority'), { target: { value: 'high' } })
|
||||||
fireEvent.submit(container.querySelector('form')!)
|
fireEvent.submit(container.querySelector('form')!)
|
||||||
await waitFor(() => expect(push).toHaveBeenCalledWith('/hse/incidents/inc1'))
|
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',
|
incident_id: 'inc1',
|
||||||
description: 'Re-coat the ramp',
|
description: 'Re-coat the ramp',
|
||||||
owner_user_id: 'u1',
|
owner_user_id: 'u1',
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ import { CapaForm } from '@/components/capa/capa-form'
|
|||||||
const users = [{ id: 'u1', name: 'Tan Mei Ling', department: 'Facilities' }]
|
const users = [{ id: 'u1', name: 'Tan Mei Ling', department: 'Facilities' }]
|
||||||
|
|
||||||
function stubFetch(postResponse: { ok: boolean; body?: unknown } = { ok: true }) {
|
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 }
|
if (url === '/api/users') return { ok: true, json: async () => users }
|
||||||
return { ok: postResponse.ok, json: async () => postResponse.body ?? {} }
|
return { ok: postResponse.ok, json: async () => postResponse.body ?? {} }
|
||||||
})
|
})
|
||||||
@@ -54,7 +55,7 @@ describe('CapaForm', () => {
|
|||||||
fireEvent.change(screen.getByLabelText('Priority'), { target: { value: 'high' } })
|
fireEvent.change(screen.getByLabelText('Priority'), { target: { value: 'high' } })
|
||||||
fireEvent.submit(container.querySelector('form')!)
|
fireEvent.submit(container.querySelector('form')!)
|
||||||
await waitFor(() => expect(push).toHaveBeenCalledWith('/hse/incidents/inc1'))
|
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',
|
incident_id: 'inc1',
|
||||||
description: 'Re-coat the ramp',
|
description: 'Re-coat the ramp',
|
||||||
owner_user_id: 'u1',
|
owner_user_id: 'u1',
|
||||||
|
|||||||
Reference in New Issue
Block a user