CodePark/ questions / External services & queues
START PRACTICINGPRACTICE
Backend question · Backend testing › External services & queues

What does nock.disableNetConnect() in a test setup file do?

Makes any HTTP request that no nock interceptor matches fail with an error instead of reaching the real network

It makes any HTTP request that no nock interceptor matches fail with an error, instead of reaching the real network. So an unexpected real call becomes a loud failure. This keeps tests deterministic (same result every run) and shows you when an interceptor is missing.

supertest talks to your own app on localhost, so this would block it too. That's why you usually allow localhost again with
nock.enableNetConnect('127.0.0.1'). It does not "prevent supertest from sending any requests at all" for good.