Skip to content
Testing·Advanced·Conceptual·1 min read

Where should a network request be mocked in a component test?

Short interview answer

At the network boundary — for example with Mock Service Worker intercepting the actual HTTP request — rather than mocking the component's own fetch wrapper or the module that calls it. Mocking at the boundary tests more real code and survives refactors of the data layer.

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Testing React components

Related questions