Skip to content

Commit 4140898

Browse files
authored
test(query-core): add test case for queryClient.isMutating (#8726)
1 parent 887820c commit 4140898

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/query-core/src/__tests__/queryClient.test.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,24 @@ describe('queryClient', () => {
415415
})
416416
})
417417

418+
describe('isMutating', () => {
419+
test('should return length of mutating', async () => {
420+
expect(queryClient.isMutating()).toBe(0)
421+
new MutationObserver(queryClient, {
422+
mutationFn: () => sleep(10).then(() => 'data'),
423+
}).mutate()
424+
expect(queryClient.isMutating()).toBe(1)
425+
new MutationObserver(queryClient, {
426+
mutationFn: () => sleep(5).then(() => 'data'),
427+
}).mutate()
428+
expect(queryClient.isMutating()).toBe(2)
429+
await vi.advanceTimersByTimeAsync(5)
430+
expect(queryClient.isMutating()).toEqual(1)
431+
await vi.advanceTimersByTimeAsync(5)
432+
expect(queryClient.isMutating()).toEqual(0)
433+
})
434+
})
435+
418436
describe('getQueryData', () => {
419437
test('should return the query data if the query is found', () => {
420438
const key = queryKey()

0 commit comments

Comments
 (0)