Repository navigation
test(client): simulate network error for undefined route in parseResponse test - #5439
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The reviewed test changes have no unresolved issues.
Review effort: Lite
Findings: None
What changed in this PR
Updates the parseResponse network-error test to deterministically simulate a failed fetch with MSW.
Changes:
- Adds a network-error handler for the undefined route.
- Updates the expected rejection snapshot.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
mhalikosen
left a comment
There was a problem hiding this comment.
Reproduced #5431 locally with a server on port 80 that answers /noRoute with a 404: main fails with [DetailedError: 404 Not Found], while this branch passes, and it also passes when the request to port 80 fails. HttpResponse.error() is MSW's own way to model a network failure, and the test still checks what it was written for: parseResponse passes a rejected fetch through unwrapped. utils.test.ts (32 tests), tsc -p tsconfig.spec.json, eslint and oxfmt pass locally.
The title got cut at parseResp… and the rest spilled into the body. The squash commit takes the title, so the full subject should be restored before merge.
|
Thanks for reproducing and reviewing! I've restored the full title. |
|
@SambhavJ2004 Thanks! |

Fixes #5431
Problem
The third case in
parseResponse > should throw error matching snapshotschecks that when
fetchitself rejects,parseResponsepasses the originalerror through unwrapped. It produced that rejection by requesting
http://localhost/noRoute, which has no MSW handler, so the request escapedto the real network and relied on nothing listening on port 80.
On machines where something does listen on port 80 (in my case IIS 10.0 on
Windows), that request receives a 404 instead, and the test fails with:
[TypeError: fetch failed][DetailedError: 404 Not Found]Fix
Add an explicit MSW handler for that route that returns
HttpResponse.error(), sofetchrejects deterministically without therequest ever reaching the network. The comment above the case is updated to
explain this.
The snapshot message changes from
fetch failed(Node's fetch, on a realconnection failure) to
Failed to fetch(MSW's simulated network error).It is still a
TypeErrorthrown at thefetchcall, which is what thiscase verifies.
Verification
On Windows 11, with vitest 5.0.1 and msw 2.15.0 installed from the lockfile:
src/client/utils.test.tspassno longer appears in either run
Before this change, the same file failed with IIS running and passed with
it stopped.
The author should do the following, if applicable
pnpm run format:fix && pnpm run lint:fixto format the code