Skip to content

Commit

Permalink
test: add test for status=error (#3411)
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT authored Apr 21, 2022
1 parent b7a07c2 commit a325801
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/react/tests/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4677,4 +4677,38 @@ describe('useQuery', () => {

consoleMock.mockRestore()
})

it('it should have status=error on mount when a query has failed', async () => {
const consoleMock = mockConsoleError()
const key = queryKey()
const states: UseQueryResult<number>[] = []
const error = new Error('oops')

const queryFn = async () => {
throw error
}

function Page() {
const state = useQuery(key, queryFn, {
retry: false,
retryOnMount: false,
})

states.push(state)

return <></>
}

await queryClient.prefetchQuery(key, queryFn)
renderWithClient(queryClient, <Page />)

await waitFor(() => expect(states).toHaveLength(1))

expect(states[0]).toMatchObject({
status: 'error',
error,
})

consoleMock.mockRestore()
})
})

1 comment on commit a325801

@vercel
Copy link

@vercel vercel bot commented on a325801 Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.