micro-test-request
Will call your micro function with a fake req
and res
.
const request = require("micro-test-request");
const handler = (req, res) => {
return "Hello world!";
}
test("200 default",async () => {
const res = await request({
method: "GET",
url: "/dev/time",
headers: {
"authorization": "Bearer OK"
},
body: { hello: "world" },
handler: handler
});
expect(res.statusCode).toBe(200);
expect(res.headers).toMatchSnapshot();
expect(res.body).toMatchSnapshot();
});
const { createRequest, createResponse } = require("micro-test-request");