1.6.7 • Published 3 months ago

jest-matcher-http v1.6.7

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months 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.7

3 months ago

1.6.6

3 months ago

1.6.5

8 months ago

1.6.4

9 months ago

1.6.3

9 months ago

1.6.2

10 months ago

1.6.1

12 months ago

1.6.0

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.14

1 year ago

1.4.13

1 year ago

1.4.12

1 year ago

1.4.11

2 years ago

1.4.10

2 years ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.7

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago