How to see if nock is matching the request or not? Is there a way one can log information on console regarding nock is matching or not to the requests being made?
The log
function is no more available on newer versions of nock e.g. v13.0.0 but you can set the DEBUG
environment variable to nock.*
as described here https://github.com/nock/nock#debugging to log each step of the matching process. For example:
export DEBUG=nock.* && yarn test
if you're using yarn to run your tests.
It is very simple.
Just add .log(console.log)
to your nock object!
nock('https://github.com')
.log(console.log)
.get('/')
Basically, nock checks all the interceptors it has active until a match is found for your request (in case you have multiple nock interceptors mocking a variety of requests). So what will be logged using .log(console.log)
is,
You can log requests to the console using:
nock.recorder.rec();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With