fetch-mock wrapper over light-my-request. This is useful to attach fetch based HTTP clients to
a tested plain HTTP or Fastify server.
const fetchMock = createFetchMockLightMyRequest((req, res) => {
res.end("Hello, World!");
});
const res = await fetchMock.fetchHandler("http://localhost/hello");
console.log(res.text());
Or with Fastify:
import Fastify from "fastify";
const fastify = Fastify();
fastify.get("/hello", () => {
return "Hello, World!";
});
const fetchMock = createFetchMockLightMyRequestFromFastify(fastify);
const res = await fetchMock.fetchHandler("http://localhost/hello");
console.log(res.text());
You can also use createFetchLightMyRequest or createFetchLightMyRequestFromFastify to directly
return the resulting mock fetch function instead of the FetchMock instance.
MIT.