Chai Assertions for Nock
Instead of manually wiring up your expectations to intercepting a nocked request:
const nockedRequest = ;nockedRequest;
you can write code that expresses what you really mean:
npm install chai-nock
Then add to your test setup:
const chai = ;const chaiNock = ;chai;
Asserts that a request has been made to the nock.
Asserts that a request has been made to the nock with a body that exactly matches the object provided.
Asserts that a request has been made to the nock with headers that exactly match the object provided.
Asserts that a request has been made to the nock with headers that contain the key/value pairs in the object provided.
Setting a Timeout
- By default, a timeout of 2 seconds is applied to assertions on nock requests. This means that if nock has not intercepted the request within the set time, the assertion will be false
- You can set a custom global timeout by calling
const chaiNock = ;chai;// Set a timeout of 10 secondschaiNock;
- WARNING: If not set already, the test timeout must be greater than that of chaiNock!
const expect = ;const nock = ;const request = ;;