Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/preact-query/src/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3263,6 +3263,31 @@ describe('useQuery', () => {
expect(states[1]).toMatchObject({ data: { count: 1 } })
})

it('should keep initialData visible alongside the error when a refetch fails', async () => {
const key = queryKey()
const states: Array<DefinedUseQueryResult<string>> = []

function Page() {
const state = useQuery({
queryKey: key,
queryFn: () =>
sleep(10).then(() => Promise.reject(new Error('Some error'))),
initialData: 'initial',
retry: false,
})
states.push(state)
return null
}

renderWithClient(queryClient, <Page />)

await vi.advanceTimersByTimeAsync(11)

expect(states.length).toBe(2)
expect(states[0]).toMatchObject({ data: 'initial', isError: false })
expect(states[1]).toMatchObject({ data: 'initial', isError: true })
})

it('should retry specified number of times', async () => {
const key = queryKey()

Expand Down
25 changes: 25 additions & 0 deletions packages/react-query/src/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3251,6 +3251,31 @@ describe('useQuery', () => {
expect(states[1]).toMatchObject({ data: { count: 1 } })
})

it('should keep initialData visible alongside the error when a refetch fails', async () => {
const key = queryKey()
const states: Array<DefinedUseQueryResult<string>> = []

function Page() {
const state = useQuery({
queryKey: key,
queryFn: () =>
sleep(10).then(() => Promise.reject(new Error('Some error'))),
initialData: 'initial',
retry: false,
})
states.push(state)
return null
}

renderWithClient(queryClient, <Page />)

await vi.advanceTimersByTimeAsync(11)

expect(states.length).toBe(2)
expect(states[0]).toMatchObject({ data: 'initial', isError: false })
expect(states[1]).toMatchObject({ data: 'initial', isError: true })
})

it('should retry specified number of times', async () => {
const key = queryKey()

Expand Down
Loading