fetch-light-my-request
v0.1.4
Published
fetch-mock wrapper over light-my-request
Downloads
3,581
Maintainers
Readme
fetch-light-my-request
fetch-mock wrapper over light-my-request. This is useful to attach fetch based HTTP clients to
a tested plain HTTP or Fastify server.
Getting Started
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.
License
MIT.
