1.6.0 • Published 12 days ago

jest-matcher-http v1.6.0

Weekly downloads
-
License
ISC
Repository
github
Last release
12 days ago

Jest matchers (toReturnHttpCode, toReturnHttpHeader) to expect http responses.

Logs received body and headers if response is not as expected.

Supported http libraries:

Supported content types:

  • application/json
  • text/plain

Installation & Configuration

With npm:

$ npm install --save-dev jest-matcher-http

Add this setting to your jest.config.js:

setupFilesAfterEnv: ['jest-matcher-http'],

There's an example typescript project here: integration_tests/tsProject/. This is used for integration testing this lib to ensure typescript compatibility.

Usage

expect(response).toReturnHttpCode(307);
expect(response).toReturnHttpHeader('Location', '/v1/new-path');

Log Output Example

expected http status code 500 to equal 307

    server responded with body:
    {
      "requestId": "<uuid>",
      "message": "Some helpful information."
    }

    server responded with headers:
    {
      "content-type": "application/json",
      ...
    }

Extended Example

const supertest = require('supertest');
const request = supertest('www.the-host.com');

describe('Example', () => {
    it('should accept empty object', async () => {
      const response = await request
        .post('/v1/objects')
        .send({});

      expect(response).toReturnHttpCode(200);
    })

    it('should redirect', async () => {
      const response = await request
        .get('/v1/old-path');

      expect(response).toReturnHttpCode(307);
      expect(response).toReturnHttpHeader('Location', '/v1/new-path');
    })
});

Contributing

Thank you for investing time to contribute to this project.

Clone the repository:

$ git clone git@github.com:rimesime/jest-matcher-http.git
$ npm ci
$ npm test

If you spot a problem, search if an issue already exists. If a related issue doesn't exist, you can open a new issue providing all relevant information to e.g. reproduce the problem or motivate your change. You are welcome to open a PR for any ticket.

License

This is free software, distributed under the ISC license.

1.6.0

12 days ago

1.5.1

16 days ago

1.5.0

1 month ago

1.4.14

1 month ago

1.4.13

2 months ago

1.4.12

4 months ago

1.4.11

6 months ago

1.4.10

7 months ago

1.4.9

10 months ago

1.4.8

10 months ago

1.4.7

1 year ago

1.4.6

1 year ago

1.4.5

1 year ago

1.4.4

1 year ago

1.4.3

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago