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

pending-tasks.test.ts

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