I have logic that conditionally makes a network request, how can I, using Nock, make a test that would fail if a network request is made? Basically asserting that 0 calls to an endpoint was made.
I was able to solve this by listening to a "no match" event being emitted from nock.
nock.emitter.on('no match', (req: any) => {
throw new Error(`Unexpected request was sent to ${req.path}`);
});
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