mirror of
https://github.com/hanzoai/msw.git
synced 2026-09-24 17:00:34 +00:00
26 lines
726 B
TypeScript
26 lines
726 B
TypeScript
import { test, expect } from '../../../../playwright.extend'
|
|
|
|
test('executes a given callback on an unhandled request', async ({
|
|
loadExample,
|
|
spyOnConsole,
|
|
fetch,
|
|
}) => {
|
|
const consoleSpy = spyOnConsole()
|
|
await loadExample(new URL('./callback.mocks.ts', import.meta.url))
|
|
|
|
const res = await fetch('https://mswjs.io/non-existing-page')
|
|
const status = res.status()
|
|
|
|
// Request is performed as-is.
|
|
expect(status).toBe(404)
|
|
|
|
// Custom callback executed.
|
|
expect(consoleSpy.get('log')).toContain(
|
|
'Oops, unhandled GET https://mswjs.io/non-existing-page',
|
|
)
|
|
|
|
// No warnings/errors produced by MSW.
|
|
expect(consoleSpy.get('error')).toBeUndefined()
|
|
expect(consoleSpy.get('warning')).toBeUndefined()
|
|
})
|