Skip to content

Commit a325801

Browse files
authored
test: add test for status=error (#3411)
1 parent b7a07c2 commit a325801

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/react/tests/useQuery.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4677,4 +4677,38 @@ describe('useQuery', () => {
46774677

46784678
consoleMock.mockRestore()
46794679
})
4680+
4681+
it('it should have status=error on mount when a query has failed', async () => {
4682+
const consoleMock = mockConsoleError()
4683+
const key = queryKey()
4684+
const states: UseQueryResult<number>[] = []
4685+
const error = new Error('oops')
4686+
4687+
const queryFn = async () => {
4688+
throw error
4689+
}
4690+
4691+
function Page() {
4692+
const state = useQuery(key, queryFn, {
4693+
retry: false,
4694+
retryOnMount: false,
4695+
})
4696+
4697+
states.push(state)
4698+
4699+
return <></>
4700+
}
4701+
4702+
await queryClient.prefetchQuery(key, queryFn)
4703+
renderWithClient(queryClient, <Page />)
4704+
4705+
await waitFor(() => expect(states).toHaveLength(1))
4706+
4707+
expect(states[0]).toMatchObject({
4708+
status: 'error',
4709+
error,
4710+
})
4711+
4712+
consoleMock.mockRestore()
4713+
})
46804714
})

0 commit comments

Comments
 (0)