Mock an external HTTP service
Mock an external HTTP API at the network layer to test success, 4xx, 5xx, timeout, and malformed-response scenarios. Keeps tests deterministic and fast.
Preview
Copy prompt
Write tests for code that makes calls to the following external API: [Paste the code and a description of the API contract]. Use [msw / nock / WireMock or equivalent] to intercept and mock HTTP requests at the network layer. Cover: a successful 2xx response, a 4xx client error, a 5xx server error, a request timeout, and a response with a malformed body. Keep the tests fully deterministic and independent of any real network.
More
Testing
Prompts
