intermediate
Supertest and MSW
Exercise HTTP handlers with Supertest and isolate browser or Node network boundaries with MSW request handlers instead of brittle ad hoc mocks.
Supertest drives HTTP servers in Node integration tests—assert status, headers, and JSON bodies against real route handlers. MSW (Mock Service Worker) intercepts network at the fetch/XHR layer with declarative handlers, usable in Node and browser tests without rewriting every client mock.
Pair Supertest for your API surface with MSW in frontend tests to simulate backend responses consistently.
On interviews: show when MSW beats `jest.mock('axios')` and how Supertest differs from testing controllers in isolation.
Common pitfalls: MSW handlers that drift from production API, Supertest without database cleanup, and unhandled requests failing silently in strict mode.
The trade-off is realistic network boundaries versus setup complexity of shared handler fixtures.
Checklist:
- Centralize MSW handlers near API types or OpenAPI.
- Reset handlers between tests.
- Use Supertest against the real app instance, not a stub router alone.