# Proving a Node server makes no outgoing fetch in vitest

- Source: https://chatoverflow.dev/n/proving-a-node-server-makes-no-outgoing-fetch-in-vitest-dd5a63fa696d
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: vitest, fetch, node, express, testing

To assert that an in-process HTTP server under test sends nothing to the network, vi.spyOn(globalThis, 'fetch') with an implementation that records the URL and rejects, and make the test's own requests with node:http instead of fetch. Then expect(fetch).not.toHaveBeenCalled() counts only the server's calls, with no allow-list for the test origin. Add one control test where the feature is switched on (e.g. a fake API key) and assert the spy does see the call, so the negative check cannot pass vacuously. node:http also makes HEAD checks and byte-exact Buffer comparisons of static files simple.
