Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

pending-tasks.test.ts

814 lines24.0 KB

1import {
2 ApplicationRef,
3 ChangeDetectionStrategy,
4 Component,
5} from '@angular/core'
6import { TestBed } from '@angular/core/testing'
7import { HttpClient, provideHttpClient } from '@angular/common/http'
8import {
9 HttpTestingController,
10 provideHttpClientTesting,
11} from '@angular/common/http/testing'
12import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
13import { sleep } from '@tanstack/query-test-utils'
14import { lastValueFrom } from 'rxjs'
15import {
16 QueryClient,
17 injectMutation,
18 injectQuery,
19 onlineManager,
20 skipToken,
21} from '..'
22import { flushQueryUpdates, setupTanStackQueryTestBed } from './test-utils'
23​
24describe('PendingTasks Integration', () => {
25 let queryClient: QueryClient
26​
27 beforeEach(() => {
28 vi.useFakeTimers()
29​
30 queryClient = new QueryClient({
31 defaultOptions: {
32 queries: {
33 retry: false,
34 },
35 mutations: {
36 retry: false,
37 },
38 },
39 })
40​
41 setupTanStackQueryTestBed(queryClient)
42 })
43​
44 afterEach(() => {
45 onlineManager.setOnline(true)
46 queryClient.clear()
47 vi.useRealTimers()
48 })
49​
50 it.each([false, true])(
51 'keeps all mutation invocations pending (reset=%s)',
52 async (reset) => {
53 vi.useRealTimers()
54 const resolve = new Map<string, (value: string) => void>()
55 const mutation = TestBed.runInInjectionContext(() =>
56 injectMutation(() => ({
57 mutationFn: (id: string) =>
58 new Promise<string>((done) => resolve.set(id, done)),
59 })),
60 )
61 const first = mutation.mutateAsync('first')
62 const second = mutation.mutateAsync('second')
63 await Promise.resolve()
64 if (reset) mutation.reset()
65 let stable = false
66 const stability = TestBed.inject(ApplicationRef)
67 .whenStable()
68 .then(() => {
69 stable = true
70 })
71 resolve.get('second')!('second')
72 await second
73 await Promise.resolve()
74 expect(stable).toBe(false)
75 expect(queryClient.isMutating()).toBe(1)
76 resolve.get('first')!('first')
77 await first
78 await stability
79 expect(stable).toBe(true)
80 },
81 )
82​
83 describe('Synchronous Resolution', () => {
84 it('should handle synchronous queryFn with whenStable()', async () => {
85 const app = TestBed.inject(ApplicationRef)
86​
87 @Component({
88 selector: 'app-test',
89 template: '',
90 changeDetection: ChangeDetectionStrategy.OnPush,
91 })
92 class TestComponent {
93 query = injectQuery(() => ({
94 queryKey: ['sync'],
95 queryFn: () => 'instant-data',
96 }))
97 }
98​
99 const fixture = TestBed.createComponent(TestComponent)
100 fixture.autoDetectChanges()
101 const query = fixture.componentInstance.query
102​
103 // Should start as pending even with synchronous data
104 expect(query.status()).toBe('pending')
105 expect(query.data()).toBeUndefined()
106​
107 const stablePromise = app.whenStable()
108 // Flush microtasks to allow TanStack Query's scheduled notifications to process
109 await Promise.resolve()
110 await vi.advanceTimersByTimeAsync(10)
111 await stablePromise
112​
113 expect(query.status()).toBe('success')
114 expect(query.data()).toBe('instant-data')
115 })
116​
117 it('should handle synchronous error with whenStable()', async () => {
118 const app = TestBed.inject(ApplicationRef)
119​
120 const query = TestBed.runInInjectionContext(() =>
121 injectQuery(() => ({
122 queryKey: ['sync-error'],
123 queryFn: () => {
124 throw new Error('instant-error')
125 },
126 })),
127 )
128​
129 const stablePromise = app.whenStable()
130 // Flush microtasks to allow TanStack Query's scheduled notifications to process
131 await Promise.resolve()
132 await vi.advanceTimersByTimeAsync(10)
133 await stablePromise
134 expect(query.status()).toBe('error')
135 expect(query.error()).toEqual(new Error('instant-error'))
136 })
137​
138 it('should handle synchronous mutationFn with whenStable()', async () => {
139 const app = TestBed.inject(ApplicationRef)
140 let mutationFnCalled = false
141​
142 const mutation = TestBed.runInInjectionContext(() =>
143 injectMutation(() => ({
144 mutationFn: async (data: string) => {
145 mutationFnCalled = true
146 await Promise.resolve()
147 return `processed: ${data}`
148 },
149 })),
150 )
151​
152 mutation.mutate('test')
153 TestBed.tick()
154​
155 const stablePromise = app.whenStable()
156 await Promise.resolve()
157 await vi.advanceTimersByTimeAsync(10)
158 await stablePromise
159 expect(mutationFnCalled).toBe(true)
160 expect(mutation.isSuccess()).toBe(true)
161 expect(mutation.data()).toBe('processed: test')
162 })
163​
164 it('should handle synchronous mutation error with whenStable()', async () => {
165 const app = TestBed.inject(ApplicationRef)
166​
167 const mutation = TestBed.runInInjectionContext(() =>
168 injectMutation(() => ({
169 mutationFn: async () => {
170 await Promise.resolve()
171 throw new Error('sync-mutation-error')
172 },
173 })),
174 )
175​
176 mutation.mutate()
177 TestBed.tick()
178​
179 const stablePromise = app.whenStable()
180 await Promise.resolve()
181 await vi.advanceTimersByTimeAsync(10)
182 await stablePromise
183 expect(mutation.isError()).toBe(true)
184 expect(mutation.error()).toEqual(new Error('sync-mutation-error'))
185 })
186​
187 it('should keep whenStable pending after mutate starts', async () => {
188 const app = TestBed.inject(ApplicationRef)
189​
190 const mutation = TestBed.runInInjectionContext(() =>
191 injectMutation(() => ({
192 mutationFn: async () => {
193 await sleep(20)
194 return 'done'
195 },
196 })),
197 )
198​
199 mutation.mutate()
200​
201 let stableResolved = false
202 const stablePromise = app.whenStable().then(() => {
203 stableResolved = true
204 })
205​
206 await Promise.resolve()
207 expect(stableResolved).toBe(false)
208​
209 await vi.advanceTimersByTimeAsync(21)
210 await vi.advanceTimersByTimeAsync(0)
211 await stablePromise
212 expect(mutation.isSuccess()).toBe(true)
213 expect(mutation.data()).toBe('done')
214 })
215 })
216​
217 describe('Race Conditions', () => {
218 it('should not register a pending task while query is disabled by enabled', async () => {
219 const queryFn = vi.fn(async () => {
220 await sleep(10)
221 return 'disabled-data'
222 })
223​
224 @Component({
225 template: '',
226 changeDetection: ChangeDetectionStrategy.OnPush,
227 })
228 class TestComponent {
229 query = injectQuery(() => ({
230 queryKey: ['disabled-enabled'],
231 queryFn,
232 enabled: false,
233 }))
234 }
235​
236 const fixture = TestBed.createComponent(TestComponent)
237 fixture.detectChanges()
238 const query = fixture.componentInstance.query
239​
240 await Promise.resolve()
241​
242 expect(query.status()).toBe('pending')
243 expect(query.fetchStatus()).toBe('idle')
244 expect(query.isPending()).toBe(true)
245 expect(queryFn).not.toHaveBeenCalled()
246 expect(fixture.isStable()).toBe(true)
247 })
248​
249 it('should not register a pending task while query is disabled by skipToken', async () => {
250 @Component({
251 template: '',
252 changeDetection: ChangeDetectionStrategy.OnPush,
253 })
254 class TestComponent {
255 query = injectQuery(() => ({
256 queryKey: ['disabled-skip-token'],
257 queryFn: skipToken,
258 }))
259 }
260​
261 const fixture = TestBed.createComponent(TestComponent)
262 fixture.detectChanges()
263 const query = fixture.componentInstance.query
264​
265 await Promise.resolve()
266​
267 expect(query.status()).toBe('pending')
268 expect(query.fetchStatus()).toBe('idle')
269 expect(query.isPending()).toBe(true)
270 expect(query.isEnabled()).toBe(false)
271 expect(fixture.isStable()).toBe(true)
272 })
273​
274 it('should handle query that completes during initial subscription', async () => {
275 const app = TestBed.inject(ApplicationRef)
276 let resolveQuery: (value: string) => void
277​
278 const queryPromise = new Promise<string>((resolve) => {
279 resolveQuery = resolve
280 })
281​
282 const query = TestBed.runInInjectionContext(() =>
283 injectQuery(() => ({
284 queryKey: ['race-condition'],
285 queryFn: () => queryPromise,
286 })),
287 )
288​
289 // Resolve immediately to create potential race condition
290 resolveQuery!('race-data')
291​
292 const stablePromise = app.whenStable()
293 await Promise.resolve()
294 await vi.advanceTimersByTimeAsync(10)
295 await stablePromise
296 expect(query.status()).toBe('success')
297 expect(query.data()).toBe('race-data')
298 })
299​
300 it('should handle rapid refetches without task leaks', async () => {
301 const app = TestBed.inject(ApplicationRef)
302​
303 @Component({
304 selector: 'app-test',
305 template: '',
306 changeDetection: ChangeDetectionStrategy.OnPush,
307 })
308 class TestComponent {
309 callCount = 0
310 query = injectQuery(() => ({
311 queryKey: ['rapid-refetch'],
312 queryFn: async () => {
313 this.callCount++
314 await sleep(10)
315 return `data-${this.callCount}`
316 },
317 }))
318 }
319​
320 const fixture = TestBed.createComponent(TestComponent)
321 fixture.autoDetectChanges()
322 const query = fixture.componentInstance.query
323​
324 // Trigger multiple rapid refetches
325 query.refetch()
326 query.refetch()
327 query.refetch()
328​
329 const stablePromise = app.whenStable()
330 await vi.advanceTimersByTimeAsync(20)
331 await stablePromise
332 expect(query.status()).toBe('success')
333 expect(query.data()).toMatch(/^data-\d+$/)
334 })
335​
336 it('should keep PendingTasks active when query starts offline (never reaches fetching)', async () => {
337 const app = TestBed.inject(ApplicationRef)
338​
339 onlineManager.setOnline(false)
340​
341 const query = TestBed.runInInjectionContext(() =>
342 injectQuery(() => ({
343 queryKey: ['start-offline'],
344 networkMode: 'online', // Default: won't fetch while offline
345 queryFn: async () => {
346 await sleep(10)
347 return 'online-data'
348 },
349 })),
350 )
351​
352 // Allow query to initialize
353 await Promise.resolve()
354 await flushQueryUpdates()
355​
356 // Query should initialize directly to 'paused' (never goes through 'fetching')
357 expect(query.status()).toBe('pending')
358 expect(query.fetchStatus()).toBe('paused')
359​
360 const stablePromise = app.whenStable()
361 let stableResolved = false
362 void stablePromise.then(() => {
363 stableResolved = true
364 })
365​
366 await Promise.resolve()
367​
368 // PendingTasks should block stability even though we never hit 'fetching'
369 expect(stableResolved).toBe(false)
370​
371 // Bring the app back online so the query can fetch
372 onlineManager.setOnline(true)
373​
374 await vi.advanceTimersByTimeAsync(20)
375 await Promise.resolve()
376​
377 await stablePromise
378​
379 expect(stableResolved).toBe(true)
380 expect(query.status()).toBe('success')
381 expect(query.data()).toBe('online-data')
382 })
383​
384 it('should keep PendingTasks active while query retry is paused offline', async () => {
385 const app = TestBed.inject(ApplicationRef)
386 let attempt = 0
387​
388 const query = TestBed.runInInjectionContext(() =>
389 injectQuery(() => ({
390 queryKey: ['paused-offline'],
391 retry: 1,
392 retryDelay: 50, // Longer delay to ensure we can go offline before retry
393 queryFn: async () => {
394 attempt++
395 if (attempt === 1) {
396 throw new Error('offline-fail')
397 }
398 await sleep(10)
399 return 'final-data'
400 },
401 })),
402 )
403​
404 // Allow the initial attempt to start and fail
405 await flushQueryUpdates()
406 await Promise.resolve()
407​
408 // Wait for the first attempt to complete and start retry delay
409 await vi.advanceTimersByTimeAsync(10)
410 await Promise.resolve()
411 expect(query.status()).toBe('pending')
412 expect(query.fetchStatus()).toBe('fetching')
413​
414 // Simulate the app going offline during retry delay
415 onlineManager.setOnline(false)
416​
417 // Advance past the retry delay to trigger the pause
418 await vi.advanceTimersByTimeAsync(50)
419 await Promise.resolve()
420 expect(query.fetchStatus()).toBe('paused')
421​
422 const stablePromise = app.whenStable()
423 let stableResolved = false
424 void stablePromise.then(() => {
425 stableResolved = true
426 })
427​
428 await Promise.resolve()
429​
430 // PendingTasks should continue blocking stability while the fetch is paused
431 expect(stableResolved).toBe(false)
432 expect(query.status()).toBe('pending')
433​
434 // Bring the app back online so the retry can continue
435 onlineManager.setOnline(true)
436​
437 // Give time for the retry to resume and complete
438 await vi.advanceTimersByTimeAsync(20)
439 await Promise.resolve()
440 await stablePromise
441 expect(stableResolved).toBe(true)
442 expect(query.status()).toBe('success')
443 expect(query.data()).toBe('final-data')
444 })
445 })
446​
447 describe('Component Destruction', () => {
448 it('becomes stable after destruction before an unresolved query completes', async () => {
449 vi.useRealTimers()
450 let resolveQuery!: (value: string) => void
451 const queryPromise = new Promise<string>((resolve) => {
452 resolveQuery = resolve
453 })
454​
455 @Component({ template: '' })
456 class UnresolvedQueryComponent {
457 query = injectQuery(() => ({
458 queryKey: ['unresolved-component-query'],
459 queryFn: () => queryPromise,
460 }))
461 }
462​
463 const fixture = TestBed.createComponent(UnresolvedQueryComponent)
464 fixture.detectChanges()
465 expect(fixture.isStable()).toBe(false)
466​
467 fixture.destroy()
468 await fixture.whenStable()
469 expect(fixture.isStable()).toBe(true)
470​
471 resolveQuery('eventual data')
472 await Promise.resolve()
473 })
474​
475 it('becomes stable after destruction before an unresolved mutation completes', async () => {
476 vi.useRealTimers()
477 let resolveMutation!: (value: string) => void
478 const mutationPromise = new Promise<string>((resolve) => {
479 resolveMutation = resolve
480 })
481​
482 @Component({ template: '' })
483 class UnresolvedMutationComponent {
484 mutation = injectMutation(() => ({
485 mutationFn: () => mutationPromise,
486 }))
487 }
488​
489 const fixture = TestBed.createComponent(UnresolvedMutationComponent)
490 fixture.detectChanges()
491 fixture.componentInstance.mutation.mutate()
492 expect(fixture.isStable()).toBe(false)
493​
494 fixture.destroy()
495 await fixture.whenStable()
496 expect(fixture.isStable()).toBe(true)
497​
498 resolveMutation('eventual data')
499 await Promise.resolve()
500 })
501 })
502​
503 describe('Concurrent Operations', () => {
504 it('should handle multiple queries running simultaneously', async () => {
505 const app = TestBed.inject(ApplicationRef)
506​
507 @Component({
508 selector: 'app-test',
509 template: '',
510 changeDetection: ChangeDetectionStrategy.OnPush,
511 })
512 class TestComponent {
513 query1 = injectQuery(() => ({
514 queryKey: ['concurrent-1'],
515 queryFn: async () => {
516 await sleep(30)
517 return 'data-1'
518 },
519 }))
520​
521 query2 = injectQuery(() => ({
522 queryKey: ['concurrent-2'],
523 queryFn: async () => {
524 await sleep(50)
525 return 'data-2'
526 },
527 }))
528​
529 query3 = injectQuery(() => ({
530 queryKey: ['concurrent-3'],
531 queryFn: () => 'instant-data',
532 }))
533 }
534​
535 const fixture = TestBed.createComponent(TestComponent)
536 fixture.autoDetectChanges()
537 const { query1, query2, query3 } = fixture.componentInstance
538​
539 expect(query1.status()).toBe('pending')
540 expect(query2.status()).toBe('pending')
541 expect(query3.status()).toBe('pending')
542​
543 const stablePromise = app.whenStable()
544 await vi.advanceTimersByTimeAsync(60)
545 await stablePromise
546​
547 expect(query1.status()).toBe('success')
548 expect(query1.data()).toBe('data-1')
549 expect(query2.status()).toBe('success')
550 expect(query2.data()).toBe('data-2')
551 expect(query3.status()).toBe('success')
552 expect(query3.data()).toBe('instant-data')
553 })
554​
555 it('should handle multiple mutations running simultaneously', async () => {
556 const app = TestBed.inject(ApplicationRef)
557​
558 const mutation1 = TestBed.runInInjectionContext(() =>
559 injectMutation(() => ({
560 mutationFn: async (data: string) => {
561 await sleep(30)
562 return `processed-1: ${data}`
563 },
564 })),
565 )
566​
567 const mutation2 = TestBed.runInInjectionContext(() =>
568 injectMutation(() => ({
569 mutationFn: async (data: string) => {
570 await sleep(50)
571 return `processed-2: ${data}`
572 },
573 })),
574 )
575​
576 const mutation3 = TestBed.runInInjectionContext(() =>
577 injectMutation(() => ({
578 mutationFn: async (data: string) => {
579 await Promise.resolve()
580 return `processed-3: ${data}`
581 },
582 })),
583 )
584​
585 mutation1.mutate('test1')
586 mutation2.mutate('test2')
587 mutation3.mutate('test3')
588 TestBed.tick()
589​
590 const stablePromise = app.whenStable()
591 await vi.advanceTimersByTimeAsync(60)
592 await stablePromise
593​
594 expect(mutation1.isSuccess()).toBe(true)
595 expect(mutation1.data()).toBe('processed-1: test1')
596 expect(mutation2.isSuccess()).toBe(true)
597 expect(mutation2.data()).toBe('processed-2: test2')
598 expect(mutation3.isSuccess()).toBe(true)
599 expect(mutation3.data()).toBe('processed-3: test3')
600 })
601​
602 it('should handle mixed queries and mutations', async () => {
603 const app = TestBed.inject(ApplicationRef)
604​
605 const query = TestBed.runInInjectionContext(() =>
606 injectQuery(() => ({
607 queryKey: ['mixed-query'],
608 queryFn: async () => {
609 await sleep(40)
610 return 'query-data'
611 },
612 })),
613 )
614​
615 const mutation = TestBed.runInInjectionContext(() =>
616 injectMutation(() => ({
617 mutationFn: async (data: string) => {
618 await sleep(60)
619 return `mutation: ${data}`
620 },
621 })),
622 )
623​
624 mutation.mutate('test')
625​
626 const stablePromise = app.whenStable()
627 await vi.advanceTimersByTimeAsync(70)
628 await stablePromise
629​
630 expect(query.status()).toBe('success')
631 expect(query.data()).toBe('query-data')
632 expect(mutation.isSuccess()).toBe(true)
633 expect(mutation.data()).toBe('mutation: test')
634 })
635 })
636​
637 describe('HttpClient Integration', () => {
638 beforeEach(() => {
639 setupTanStackQueryTestBed(queryClient, {
640 providers: [provideHttpClient(), provideHttpClientTesting()],
641 })
642 })
643​
644 it('should handle multiple HttpClient requests with lastValueFrom', async () => {
645 const app = TestBed.inject(ApplicationRef)
646 const httpClient = TestBed.inject(HttpClient)
647 const httpTestingController = TestBed.inject(HttpTestingController)
648​
649 const query1 = TestBed.runInInjectionContext(() =>
650 injectQuery(() => ({
651 queryKey: ['http-1'],
652 queryFn: () =>
653 lastValueFrom(httpClient.get<{ id: number }>('/api/1')),
654 })),
655 )
656​
657 const query2 = TestBed.runInInjectionContext(() =>
658 injectQuery(() => ({
659 queryKey: ['http-2'],
660 queryFn: () =>
661 lastValueFrom(httpClient.get<{ id: number }>('/api/2')),
662 })),
663 )
664​
665 setTimeout(() => {
666 const req1 = httpTestingController.expectOne('/api/1')
667 req1.flush({ id: 1 })
668​
669 const req2 = httpTestingController.expectOne('/api/2')
670 req2.flush({ id: 2 })
671 }, 10)
672​
673 const stablePromise = app.whenStable()
674 await vi.advanceTimersByTimeAsync(20)
675 await stablePromise
676 expect(query1.status()).toBe('success')
677 expect(query1.data()).toEqual({ id: 1 })
678 expect(query2.status()).toBe('success')
679 expect(query2.data()).toEqual({ id: 2 })
680​
681 httpTestingController.verify()
682 })
683​
684 it('should handle HttpClient request cancellation', async () => {
685 const app = TestBed.inject(ApplicationRef)
686 const httpClient = TestBed.inject(HttpClient)
687 const httpTestingController = TestBed.inject(HttpTestingController)
688​
689 const query = TestBed.runInInjectionContext(() =>
690 injectQuery(() => ({
691 queryKey: ['http-cancel'],
692 queryFn: () =>
693 lastValueFrom(httpClient.get<{ data: string }>('/api/cancel')),
694 })),
695 )
696​
697 // Cancel the request before it completes
698 setTimeout(() => {
699 const req = httpTestingController.expectOne('/api/cancel')
700 req.error(new ProgressEvent('error'), {
701 status: 0,
702 statusText: 'Unknown Error',
703 })
704 }, 10)
705​
706 const stablePromise = app.whenStable()
707 await vi.advanceTimersByTimeAsync(20)
708 await stablePromise
709 expect(query.status()).toBe('error')
710​
711 httpTestingController.verify()
712 })
713 })
714​
715 describe('Edge Cases', () => {
716 it('should handle query cancellation mid-flight', async () => {
717 const app = TestBed.inject(ApplicationRef)
718​
719 const query = TestBed.runInInjectionContext(() =>
720 injectQuery(() => ({
721 queryKey: ['cancel-test'],
722 queryFn: async () => {
723 await sleep(100)
724 return 'data'
725 },
726 })),
727 )
728​
729 // Cancel the query after a short delay
730 setTimeout(() => {
731 queryClient.cancelQueries({ queryKey: ['cancel-test'] })
732 }, 20)
733​
734 // Advance to the cancellation point
735 await vi.advanceTimersByTimeAsync(20)
736​
737 const stablePromise = app.whenStable()
738 await vi.advanceTimersByTimeAsync(130)
739 await stablePromise
740​
741 // Cancellation should restore the pre-fetch state
742 expect(query.status()).toBe('pending')
743 expect(query.fetchStatus()).toBe('idle')
744 })
745​
746 it('should handle query retry and pending task tracking', async () => {
747 const app = TestBed.inject(ApplicationRef)
748 let attemptCount = 0
749​
750 const query = TestBed.runInInjectionContext(() =>
751 injectQuery(() => ({
752 queryKey: ['retry-test'],
753 retry: 2,
754 retryDelay: 10,
755 queryFn: async () => {
756 attemptCount++
757 if (attemptCount <= 2) {
758 throw new Error(`Attempt ${attemptCount} failed`)
759 }
760 return 'success-data'
761 },
762 })),
763 )
764​
765 const stablePromise = app.whenStable()
766 await vi.advanceTimersByTimeAsync(50)
767 await stablePromise
768 expect(query.status()).toBe('success')
769 expect(query.data()).toBe('success-data')
770 expect(attemptCount).toBe(3) // Initial + 2 retries
771 })
772​
773 it('should handle mutation with optimistic updates', async () => {
774 const app = TestBed.inject(ApplicationRef)
775 const testQueryKey = ['optimistic-test']
776​
777 queryClient.setQueryData(testQueryKey, 'initial-data')
778​
779 const mutation = TestBed.runInInjectionContext(() =>
780 injectMutation(() => ({
781 mutationFn: async (newData: string) => {
782 await sleep(50)
783 return newData
784 },
785 onMutate: async (newData) => {
786 // Optimistic update
787 const previousData = queryClient.getQueryData(testQueryKey)
788 queryClient.setQueryData(testQueryKey, newData)
789 return { previousData }
790 },
791 onError: (_err, _newData, context) => {
792 // Rollback on error
793 if (context?.previousData) {
794 queryClient.setQueryData(testQueryKey, context.previousData)
795 }
796 },
797 })),
798 )
799​
800 mutation.mutate('optimistic-data')
801 await Promise.resolve()
802​
803 // Data should be optimistically updated immediately
804 expect(queryClient.getQueryData(testQueryKey)).toBe('optimistic-data')
805​
806 const stablePromise = app.whenStable()
807 await vi.advanceTimersByTimeAsync(60)
808 await stablePromise
809 expect(mutation.isSuccess()).toBe(true)
810 expect(mutation.data()).toBe('optimistic-data')
811 expect(queryClient.getQueryData(testQueryKey)).toBe('optimistic-data')
812 })
813 })
814})