Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

test(react-query): add test case for useSuspenseQuery #8731

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
31 changes: 31 additions & 0 deletions packages/react-query/src/__tests__/useSuspenseQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -888,4 +888,35 @@ describe('useSuspenseQuery', () => {
)
consoleErrorSpy.mockRestore()
})
it('should properly refresh data when refetchInterval is set', async () => {
const key = queryKey()
let count = 0

function Page() {
const state = useSuspenseQuery({
queryKey: key,
queryFn: async () => {
count++
await sleep(1)
return count
},
refetchInterval: 10,
})

return <div>count: {state.data}</div>
}

const rendered = renderWithClient(
queryClient,
<React.Suspense fallback="Loading...">
<Page />
</React.Suspense>,
)

await waitFor(() => rendered.getByText('count: 1'))
await waitFor(() => rendered.getByText('count: 2'))
await waitFor(() => rendered.getByText('count: 3'))

expect(count).toBeGreaterThanOrEqual(3)
})
})
Loading