Skip to content

Commit ff619d0

Browse files
committed
test: add test for infinite queries and suspense
1 parent 2bcc893 commit ff619d0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/react/tests/suspense.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
QueryErrorResetBoundary,
1111
useQueryErrorResetBoundary,
1212
UseQueryResult,
13+
UseInfiniteQueryResult,
14+
useInfiniteQuery,
1315
} from '../..'
1416

1517
describe("useQuery's in Suspense mode", () => {
@@ -65,6 +67,39 @@ describe("useQuery's in Suspense mode", () => {
6567
expect(states[1]).toMatchObject({ data: 2, status: 'success' })
6668
})
6769

70+
it('should return the correct states for a successful infinite query', async () => {
71+
const key = queryKey()
72+
const states: UseInfiniteQueryResult<number>[] = []
73+
74+
function Page() {
75+
const state = useInfiniteQuery(
76+
key,
77+
({ pageParam = 0 }) => Number(pageParam),
78+
{
79+
suspense: true,
80+
getNextPageParam: lastPage => lastPage + 1,
81+
}
82+
)
83+
states.push(state)
84+
return null
85+
}
86+
87+
renderWithClient(
88+
queryClient,
89+
<React.Suspense fallback="loading">
90+
<Page />
91+
</React.Suspense>
92+
)
93+
94+
await sleep(10)
95+
96+
expect(states.length).toBe(1)
97+
expect(states[0]).toMatchObject({
98+
data: { pages: [0], pageParams: [undefined] },
99+
status: 'success',
100+
})
101+
})
102+
68103
it('should not call the queryFn twice when used in Suspense mode', async () => {
69104
const key = queryKey()
70105

0 commit comments

Comments
 (0)