You can see every mock that is currently active (i.e.
You can see every mock that is currently active (i.e. might potentially reply to requests) in a scope using scope.activeMocks(). A mock is active if it is pending, optional but not yet completed, or persisted. Mocks that have intercepted their requests and are no longer doing anything are the only mocks which won't appear here. You probably don't need to use this - it mainly exists as a mechanism to recreate the previous (now-changed) behavior of pendingMocks().
the array of active mocks
Basic authentication can be specified
Basic authentication can be specified
the basic authentication options
You can cleanup all the prepared mocks (could be useful to cleanup some state after a failed test)
You are able to specify the number of milliseconds that the response body should be delayed.
You are able to specify the number of milliseconds that the response body should be delayed. Response header will be replied immediately. delayBody(1000) is equivalent to delay({body: 1000}).
an object containing the delay in milliseconds
You are able to specify the number of milliseconds that the response body should be delayed.
You are able to specify the number of milliseconds that the response body should be delayed. Response header will be replied immediately. delayBody(1000) is equivalent to delay({body: 1000}).
the given delay in milliseconds
HTTP DELETE
HTTP DELETE
the given url
By default, any requests made to a host that is not mocked will be executed normally.
By default, any requests made to a host that is not mocked will be executed normally. If you want to block these requests, nock allows you to do so.
For disabling real http requests.
For enabling real HTTP requests (the default behaviour).
HTTP GET
HTTP GET
the given url
HTTP HEAD
HTTP HEAD
the given url
You can call isDone() on a single expectation to determine if the expectation was met
You can call isDone() on a single expectation to determine if the expectation was met
true, if the expectation was met
If you save this as a JSON file, you can load them directly through nock.load(path).
If you save this as a JSON file, you can load them directly through nock.load(path). Then you can post-process them before using them in the tests for example to add them request body filtering (shown here fixing timestamps to match the ones captured during recording)
the path to the JSON file
the loaded object
Nock can log matches if you pass in a log function
Nock can log matches if you pass in a log function
the given logger function
Nock.log(console.log)
HTTP PATCH
HTTP PATCH
the given url
You can inspect the scope to infer which ones are still pending
You can inspect the scope to infer which ones are still pending
the array of pending mocks
You can make all the interceptors for a scope persist by calling .persist() on it
You can make all the interceptors for a scope persist by calling .persist() on it
self
HTTP POST
HTTP POST
the given url
This is a cool feature: Guessing what the HTTP calls are is a mess, specially if you are introducing nock on your already-coded tests.
This is a cool feature: Guessing what the HTTP calls are is a mess, specially if you are introducing nock on your already-coded tests. For these cases where you want to mock an existing live system you can record and playback the HTTP calls like this:
the recorder instance
You can restore the HTTP interceptor to the normal unmocked behaviour
Nock is an HTTP mocking and expectations library for Node.js