mirror of
https://github.com/hanzoai/msw.git
synced 2026-09-24 17:00:34 +00:00
Co-authored-by: Frederik Rabøl <[email protected]> Co-authored-by: Christoph Fricke <[email protected]> Co-authored-by: Piotr <[email protected]> Co-authored-by: Kristján Oddsson <[email protected]> Co-authored-by: thepassle <[email protected]> Co-authored-by: Kevin Østerkilde <[email protected]> Co-authored-by: Laryssa Rocha <[email protected]> Co-authored-by: Matthew Costabile <[email protected]>
24 lines
704 B
TypeScript
24 lines
704 B
TypeScript
import { http, HttpResponse } from 'msw'
|
|
import { setupWorker } from 'msw/browser'
|
|
|
|
const worker = setupWorker(
|
|
http.get('/user', () => {
|
|
return HttpResponse.json({ firstName: 'John' })
|
|
}),
|
|
http.post('/explicit-return', () => {
|
|
// Short-circuiting in a handler makes it perform the request as-is,
|
|
// but still treats this request as handled.
|
|
return
|
|
}),
|
|
http.post('/implicit-return', () => {
|
|
// The handler that has no return also performs the request as-is,
|
|
// still treating this request as handled.
|
|
}),
|
|
)
|
|
|
|
worker.start({
|
|
// Warn on the requests that are not handled in the request handlers above.
|
|
// Does not cancel the request.
|
|
onUnhandledRequest: 'warn',
|
|
})
|