@orikami/micro-test-request

1.2.0 • Public • Published

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");

Readme

Keywords

none

Package Sidebar

Install

npm i @orikami/micro-test-request

Weekly Downloads

0

Version

1.2.0

License

MIT

Unpacked Size

2.76 kB

Total Files

3

Last publish

Collaborators

  • logmaor
  • markmarijnissen
  • stijnavdl