0.1.1 • Published 7 years ago

micro-test-request v0.1.1

Weekly downloads
31
License
MIT
Repository
-
Last release
7 years ago

micro-test-request

Will call your micro function with a fake req and res.

const request = require("micro-test-request");

// Your micro function in `index.js`
const handler = (req, res) => {
    return "Hello world!";
}

// Test using `jest` like this:
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();
});

// You can also use the fake response and request directly
const { createRequest, createResponse } = require("micro-test-request");