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(query-core): add test case for queryClient.isFetching #8720

Merged
21 changes: 21 additions & 0 deletions packages/query-core/src/__tests__/queryClient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,27 @@ describe('queryClient', () => {
})
})

describe('isFetching', () => {
test('should return length of fetching queries', async () => {
const key1 = queryKey()
const key2 = queryKey()

expect(queryClient.isFetching()).toBe(0)
queryClient.prefetchQuery({
queryKey: key1,
queryFn: () => sleep(30).then(() => 'data'),
})
expect(queryClient.isFetching()).toBe(1)
queryClient.prefetchQuery({
queryKey: key2,
queryFn: () => sleep(25).then(() => 'data'),
})
expect(queryClient.isFetching()).toBe(2)
await waitFor(() => expect(queryClient.isFetching()).toEqual(1))
await waitFor(() => expect(queryClient.isFetching()).toEqual(0))
})
})

describe('getQueryData', () => {
test('should return the query data if the query is found', () => {
const key = queryKey()
Expand Down
Loading