Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions packages/react-query/src/__tests__/useSuspenseQuery.test.tsx
Original file line number Diff line number Diff line change
@@ -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
Oops, something went wrong.