Skip to content
Myr

test(client): simulate network error for undefined route in parseResponse test (#5439)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sambhav Jain · committed by GitHub · parent 6abd35b · Browse files · 1 file+4 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−3 removed

  • tests:+4 added−3 removed

1 file+4 added−3 removed

modified:src/client/utils.test.ts+4 added-3 removed
290 unmodified lines
291 headers: {292 'content-type': 'x/custom-type',293 },294 })295 })295 }),296 http.get('http://localhost/noRoute', () => HttpResponse.error())297 )298299 beforeAll(() => server.listen())300 afterEach(() => server.resetHandlers())
48 unmodified lines
349 await expect(parseResponse(client['500'].$get())).rejects.toThrowErrorMatchingInlineSnapshot(350 '[DetailedError: 500 Internal Server Error]'351 )352352 // Not defined route353 // Not defined route: MSW simulates a network error, so fetch itself rejects354 // Note: the error in this test case is thrown at the `fetch` call (.$get()), not during the `parseResponse` call, so I think `parseResponse` should not try to catch and wrap it into a structured error, which could be inconsistent, if the user awaited the fetch.355 await expect(356 // @ts-expect-error noRoute is not defined357 parseResponse(client['noRoute'].$get())357 ).rejects.toThrowErrorMatchingInlineSnapshot('[TypeError: fetch failed]')358 ).rejects.toThrowErrorMatchingInlineSnapshot('[TypeError: Failed to fetch]')359 }),360 it('(type-only) should bypass error responses in the result type inference - simple 404', async () => {361 type ResultType = Awaited<362 ReturnType<typeof parseResponse<Awaited<ReturnType<(typeof client)['404']['$get']>>>>
43 unmodified lines