Standard-first API mocking
MSW doesn't reinvent the wheel. How do you handle the network in JavaScript? With the Fetch API! And that's precisely how you write your mocks.
http.post('/user/:id', async ({ request, params }) => {
const user = await request.clone().json()
const headers = request.headers
headers.set('x-mocked', 'true')
return Response.json(
{ ...user, id: params.id },
{ headers },
)
})
