Files
http.md/tests/mocks/handlers.ts
2025-05-19 21:04:32 +02:00

26 lines
616 B
TypeScript

import { http, HttpResponse } from 'msw';
export const handlers = [
http.all('https://httpbin.org/*', async (req) => {
const bodyRaw = await req.request.text();
let bodyJson: unknown = undefined;
try {
bodyJson = JSON.parse(bodyRaw);
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
} catch (e) {
// Ignore error
}
return HttpResponse.text(
JSON.stringify(
{
headers: Object.fromEntries(req.request.headers.entries()),
data: bodyRaw,
json: bodyJson,
},
null,
2,
),
);
}),
];