1.2.0 ā€¢ Published 4 years ago

pify-express-handler v1.2.0

Weekly downloads
27
License
MIT
Repository
github
Last release
4 years ago

Pify Express Handler

A 0-dependency promisify package for easier testing of express handlers used in Firebase Functions & Google Cloud Functions.

āš ļø Warning: express middleware not supported.

Usage:

import { promisifyHandler } from "pify-express-handler"

const someHandler = async (req, res) => {
    await ...; // some call to a server
    res.status(201).send("It's been created!");
}

// Test
it("should create the resource if everything succeeds", async () => {
    const handler = promisifyHandler(someHandler);

    const {status, body, headers} = await handler({/* empty request will suffice for this test*/});

    expect(status).to.equal(201);
    expect(body).to.equal("It's been created!");
    expect(headers['foo']).to.equal('bar');
})

Why?

When you want to test your function you have a couple approaches.

Instead; you can use this package to make testing your function smooth as butter šŸ§ˆ.

Limitations

Currently, only the following functions are supported:

  • .write()
  • .status()
  • .end()
  • .set()
  • .send()
  • .json()

If your function uses any other of the res object's functions this package will throw an error.

I'm happy to add more support later, if this package picks up. Please let me know through submitting an issue! šŸ˜€

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.2

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago