Open History to see the last commit
1import {
2 ApplicationRef,
3 Component,
4 Injector,
5 input,
6 provideZonelessChangeDetection,
7 signal,
8} from '@angular/core'
9import { TestBed } from '@angular/core/testing'
10import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
11import { By } from '@angular/platform-browser'
12import { render } from '@testing-library/angular'
13import { queryKey, sleep } from '@tanstack/query-test-utils'
14import { QueryClient, injectMutation, provideTanStackQuery } from '..'
15import { expectSignals, setFixtureSignalInputs } from './test-utils'
16β
17describe('injectMutation', () => {
18 let queryClient: QueryClient
19β
20 beforeEach(() => {
21 queryClient = new QueryClient()
22 vi.useFakeTimers()
23 TestBed.configureTestingModule({
24 providers: [
25 provideZonelessChangeDetection(),
26 provideTanStackQuery(queryClient),
27 ],
28 })
29 })
30β
31 afterEach(() => {
32 vi.useRealTimers()
33 })
34β
35 it('should be in idle state initially', () => {
36 const mutation = TestBed.runInInjectionContext(() => {
37 return injectMutation(() => ({
38 mutationFn: (params) => sleep(0).then(() => params),
39 }))
40 })
41β
42 expectSignals(mutation, {
43 isIdle: true,
44 isPending: false,
45 isError: false,
46 isSuccess: false,
47 })
48 })
49β
50 it('should change state after invoking mutate', async () => {
51 const result = 'Mock data'
52β
53 @Component({
54 template: `
55 <div>isIdle: {{ mutation.isIdle() }}</div>
56 <div>isPending: {{ mutation.isPending() }}</div>
57 <div>isError: {{ mutation.isError() }}</div>
58 <div>isSuccess: {{ mutation.isSuccess() }}</div>
59 <div>data: {{ mutation.data() ?? 'none' }}</div>
60 <div>error: {{ mutation.error()?.message ?? 'none' }}</div>
61 `,
62 })
63 class Page {
64 readonly mutation = injectMutation(() => ({
65 mutationFn: (params: string) => sleep(10).then(() => params),
66 }))
67 }
68β
69 const rendered = await render(Page)
70β
71 rendered.fixture.componentInstance.mutation.mutate(result)
72 await vi.advanceTimersByTimeAsync(0)
73 rendered.fixture.detectChanges()
74β
75 expect(rendered.getByText('isIdle: false')).toBeInTheDocument()
76 expect(rendered.getByText('isPending: true')).toBeInTheDocument()
77 expect(rendered.getByText('isError: false')).toBeInTheDocument()
78 expect(rendered.getByText('isSuccess: false')).toBeInTheDocument()
79 expect(rendered.getByText('data: none')).toBeInTheDocument()
80 expect(rendered.getByText('error: none')).toBeInTheDocument()
81 })
82β
83 it('should return error when request fails', async () => {
84 @Component({
85 template: `
86 <div>isIdle: {{ mutation.isIdle() }}</div>
87 <div>isPending: {{ mutation.isPending() }}</div>
88 <div>isError: {{ mutation.isError() }}</div>
89 <div>isSuccess: {{ mutation.isSuccess() }}</div>
90 <div>data: {{ mutation.data() ?? 'none' }}</div>
91 <div>error: {{ mutation.error()?.message ?? 'none' }}</div>
92 `,
93 })
94 class Page {
95 readonly mutation = injectMutation(() => ({
96 mutationFn: () =>
97 sleep(10).then(() => Promise.reject(new Error('Some error'))),
98 }))
99 }
100β
101 const rendered = await render(Page)
102β
103 rendered.fixture.componentInstance.mutation.mutate()
104β
105 await vi.advanceTimersByTimeAsync(11)
106 rendered.fixture.detectChanges()
107β
108 expect(rendered.getByText('isIdle: false')).toBeInTheDocument()
109 expect(rendered.getByText('isPending: false')).toBeInTheDocument()
110 expect(rendered.getByText('isError: true')).toBeInTheDocument()
111 expect(rendered.getByText('isSuccess: false')).toBeInTheDocument()
112 expect(rendered.getByText('data: none')).toBeInTheDocument()
113 expect(rendered.getByText('error: Some error')).toBeInTheDocument()
114 })
115β
116 it('should return data when request succeeds', async () => {
117 const result = 'Mock data'
118β
119 @Component({
120 template: `
121 <div>isIdle: {{ mutation.isIdle() }}</div>
122 <div>isPending: {{ mutation.isPending() }}</div>
123 <div>isError: {{ mutation.isError() }}</div>
124 <div>isSuccess: {{ mutation.isSuccess() }}</div>
125 <div>data: {{ mutation.data() ?? 'none' }}</div>
126 <div>error: {{ mutation.error()?.message ?? 'none' }}</div>
127 `,
128 })
129 class Page {
130 readonly mutation = injectMutation(() => ({
131 mutationFn: (params: string) => sleep(10).then(() => params),
132 }))
133 }
134β
135 const rendered = await render(Page)
136β
137 rendered.fixture.componentInstance.mutation.mutate(result)
138β
139 await vi.advanceTimersByTimeAsync(11)
140 rendered.fixture.detectChanges()
141β
142 expect(rendered.getByText('isIdle: false')).toBeInTheDocument()
143 expect(rendered.getByText('isPending: false')).toBeInTheDocument()
144 expect(rendered.getByText('isError: false')).toBeInTheDocument()
145 expect(rendered.getByText('isSuccess: true')).toBeInTheDocument()
146 expect(rendered.getByText(`data: ${result}`)).toBeInTheDocument()
147 expect(rendered.getByText('error: none')).toBeInTheDocument()
148 })
149β
150 it('should update mutation when reactive options change', () => {
151 const mutationCache = queryClient.getMutationCache()
152 // Signal will be updated before the mutation is called
153 // this test confirms that the mutation uses the updated value
154 const key1 = queryKey()
155 const key2 = queryKey()
156 const mutationKey = signal(key1)
157 const mutation = TestBed.runInInjectionContext(() => {
158 return injectMutation(() => ({
159 mutationKey: mutationKey(),
160 mutationFn: (params: string) => sleep(0).then(() => params),
161 }))
162 })
163β
164 mutationKey.set(key2)
165β
166 mutation.mutate('xyz')
167β
168 const mutations = mutationCache.find({ mutationKey: key2 })
169β
170 expect(mutations?.options.mutationKey).toEqual(key2)
171 })
172β
173 it('should reset state after invoking mutation.reset', async () => {
174 @Component({
175 template: `
176 <div>isIdle: {{ mutation.isIdle() }}</div>
177 <div>isPending: {{ mutation.isPending() }}</div>
178 <div>isError: {{ mutation.isError() }}</div>
179 <div>isSuccess: {{ mutation.isSuccess() }}</div>
180 <div>data: {{ mutation.data() ?? 'none' }}</div>
181 <div>error: {{ mutation.error()?.message ?? 'none' }}</div>
182 `,
183 })
184 class Page {
185 readonly mutation = injectMutation(() => ({
186 mutationFn: () =>
187 sleep(10).then(() => Promise.reject(new Error('Some error'))),
188 }))
189 }
190β
191 const rendered = await render(Page)
192β
193 rendered.fixture.componentInstance.mutation.mutate()
194β
195 await vi.advanceTimersByTimeAsync(11)
196 rendered.fixture.detectChanges()
197β
198 expect(rendered.getByText('isError: true')).toBeInTheDocument()
199 expect(rendered.getByText('error: Some error')).toBeInTheDocument()
200β
201 rendered.fixture.componentInstance.mutation.reset()
202β
203 await vi.advanceTimersByTimeAsync(0)
204 rendered.fixture.detectChanges()
205β
206 expect(rendered.getByText('isIdle: true')).toBeInTheDocument()
207 expect(rendered.getByText('isPending: false')).toBeInTheDocument()
208 expect(rendered.getByText('isError: false')).toBeInTheDocument()
209 expect(rendered.getByText('isSuccess: false')).toBeInTheDocument()
210 expect(rendered.getByText('data: none')).toBeInTheDocument()
211 expect(rendered.getByText('error: none')).toBeInTheDocument()
212 })
213β
214 describe('side effects', () => {
215 beforeEach(() => {
216 vi.clearAllMocks()
217 })
218β
219 it('should call onMutate when passed as an option', async () => {
220 const onMutate = vi.fn()
221 const mutation = TestBed.runInInjectionContext(() => {
222 return injectMutation(() => ({
223 mutationFn: (params: string) => sleep(10).then(() => params),
224 onMutate,
225 }))
226 })
227β
228 mutation.mutate('')
229β
230 await vi.advanceTimersByTimeAsync(0)
231β
232 expect(onMutate).toHaveBeenCalledTimes(1)
233 })
234β
235 it('should call onError when passed as an option', async () => {
236 const onError = vi.fn()
237 const mutation = TestBed.runInInjectionContext(() => {
238 return injectMutation(() => ({
239 mutationFn: (_params: string) =>
240 sleep(10).then(() => Promise.reject(new Error('Some error'))),
241 onError,
242 }))
243 })
244β
245 mutation.mutate('')
246β
247 await vi.advanceTimersByTimeAsync(11)
248β
249 expect(onError).toHaveBeenCalledTimes(1)
250 })
251β
252 it('should call onSuccess when passed as an option', async () => {
253 const onSuccess = vi.fn()
254 const mutation = TestBed.runInInjectionContext(() => {
255 return injectMutation(() => ({
256 mutationFn: (params: string) => sleep(10).then(() => params),
257 onSuccess,
258 }))
259 })
260β
261 mutation.mutate('')
262β
263 await vi.advanceTimersByTimeAsync(11)
264β
265 expect(onSuccess).toHaveBeenCalledTimes(1)
266 })
267β
268 it('should call onSettled when passed as an option', async () => {
269 const onSettled = vi.fn()
270 const mutation = TestBed.runInInjectionContext(() => {
271 return injectMutation(() => ({
272 mutationFn: (params: string) => sleep(10).then(() => params),
273 onSettled,
274 }))
275 })
276β
277 mutation.mutate('')
278β
279 await vi.advanceTimersByTimeAsync(11)
280β
281 expect(onSettled).toHaveBeenCalledTimes(1)
282 })
283β
284 it('should call onError when passed as an argument of mutate function', async () => {
285 const onError = vi.fn()
286 const mutation = TestBed.runInInjectionContext(() => {
287 return injectMutation(() => ({
288 mutationFn: (_params: string) =>
289 sleep(10).then(() => Promise.reject(new Error('Some error'))),
290 }))
291 })
292β
293 mutation.mutate('', { onError })
294β
295 await vi.advanceTimersByTimeAsync(11)
296β
297 expect(onError).toHaveBeenCalledTimes(1)
298 })
299β
300 it('should call onSuccess when passed as an argument of mutate function', async () => {
301 const onSuccess = vi.fn()
302 const mutation = TestBed.runInInjectionContext(() => {
303 return injectMutation(() => ({
304 mutationFn: (params: string) => sleep(10).then(() => params),
305 }))
306 })
307β
308 mutation.mutate('', { onSuccess })
309β
310 await vi.advanceTimersByTimeAsync(11)
311β
312 expect(onSuccess).toHaveBeenCalledTimes(1)
313 })
314β
315 it('should call onSettled when passed as an argument of mutate function', async () => {
316 const onSettled = vi.fn()
317 const mutation = TestBed.runInInjectionContext(() => {
318 return injectMutation(() => ({
319 mutationFn: (params: string) => sleep(10).then(() => params),
320 }))
321 })
322β
323 mutation.mutate('', { onSettled })
324β
325 await vi.advanceTimersByTimeAsync(11)
326β
327 expect(onSettled).toHaveBeenCalledTimes(1)
328 })
329β
330 it('should fire both onSettled functions', async () => {
331 const onSettled = vi.fn()
332 const onSettledOnFunction = vi.fn()
333 const mutation = TestBed.runInInjectionContext(() => {
334 return injectMutation(() => ({
335 mutationFn: (params: string) => sleep(10).then(() => params),
336 onSettled,
337 }))
338 })
339β
340 mutation.mutate('', { onSettled: onSettledOnFunction })
341β
342 await vi.advanceTimersByTimeAsync(11)
343β
344 expect(onSettled).toHaveBeenCalledTimes(1)
345 expect(onSettledOnFunction).toHaveBeenCalledTimes(1)
346 })
347 })
348β
349 it('should support required signal inputs', async () => {
350 const mutationCache = queryClient.getMutationCache()
351β
352 @Component({
353 selector: 'app-fake',
354 template: `
355 <button (click)="mutate()"></button>
356 <span>{{ mutation.data() }}</span>
357 `,
358 })
359 class FakeComponent {
360 name = input.required<string>()
361β
362 mutation = injectMutation(() => ({
363 mutationKey: ['fake', this.name()],
364 mutationFn: () => sleep(10).then(() => this.name()),
365 }))
366β
367 mutate(): void {
368 this.mutation.mutate()
369 }
370 }
371β
372 const fixture = TestBed.createComponent(FakeComponent)
373 const { debugElement } = fixture
374 setFixtureSignalInputs(fixture, { name: 'value' })
375β
376 const button = debugElement.query(By.css('button'))
377 button.triggerEventHandler('click')
378β
379 await vi.advanceTimersByTimeAsync(11)
380 fixture.detectChanges()
381β
382 const text = debugElement.query(By.css('span')).nativeElement.textContent
383 expect(text).toEqual('value')
384 const mutation = mutationCache.find({ mutationKey: ['fake', 'value'] })
385 expect(mutation).toBeDefined()
386 expect(mutation!.options.mutationKey).toStrictEqual(['fake', 'value'])
387 })
388β
389 it('should update options on required signal input change', async () => {
390 const mutationCache = queryClient.getMutationCache()
391β
392 @Component({
393 selector: 'app-fake',
394 template: `
395 <button (click)="mutate()"></button>
396 <span>{{ mutation.data() }}</span>
397 `,
398 })
399 class FakeComponent {
400 name = input.required<string>()
401β
402 mutation = injectMutation(() => ({
403 mutationKey: ['fake', this.name()],
404 mutationFn: () => sleep(10).then(() => this.name()),
405 }))
406β
407 mutate(): void {
408 this.mutation.mutate()
409 }
410 }
411β
412 const fixture = TestBed.createComponent(FakeComponent)
413 const { debugElement } = fixture
414 setFixtureSignalInputs(fixture, { name: 'value' })
415β
416 const button = debugElement.query(By.css('button'))
417 const span = debugElement.query(By.css('span'))
418β
419 button.triggerEventHandler('click')
420 await vi.advanceTimersByTimeAsync(11)
421 fixture.detectChanges()
422β
423 expect(span.nativeElement.textContent).toEqual('value')
424β
425 setFixtureSignalInputs(fixture, { name: 'updatedValue' })
426β
427 button.triggerEventHandler('click')
428 await vi.advanceTimersByTimeAsync(11)
429 fixture.detectChanges()
430β
431 expect(span.nativeElement.textContent).toEqual('updatedValue')
432β
433 const mutations = mutationCache.findAll()
434 expect(mutations.length).toBe(2)
435 const [mutation1, mutation2] = mutations
436 expect(mutation1!.options.mutationKey).toEqual(['fake', 'value'])
437 expect(mutation2!.options.mutationKey).toEqual(['fake', 'updatedValue'])
438 })
439β
440 describe('throwOnError', () => {
441 it('should evaluate throwOnError when mutation is expected to throw', async () => {
442 const key = queryKey()
443 const err = new Error('Expected mock error. All is well!')
444 const boundaryFn = vi.fn()
445 const { mutate } = TestBed.runInInjectionContext(() => {
446 return injectMutation(() => ({
447 mutationKey: key,
448 mutationFn: () => {
449 return Promise.reject(err)
450 },
451 throwOnError: boundaryFn,
452 }))
453 })
454β
455 TestBed.tick()
456β
457 mutate()
458β
459 await vi.advanceTimersByTimeAsync(0)
460β
461 expect(boundaryFn).toHaveBeenCalledTimes(1)
462 expect(boundaryFn).toHaveBeenCalledWith(err)
463 })
464β
465 it('should throw when throwOnError is true and mutate is used', async () => {
466 const key = queryKey()
467 const { mutate } = TestBed.runInInjectionContext(() => {
468 return injectMutation(() => ({
469 mutationKey: key,
470 mutationFn: () => {
471 return Promise.reject(
472 new Error('Expected mock error. All is well!'),
473 )
474 },
475 throwOnError: true,
476 }))
477 })
478β
479 TestBed.tick()
480β
481 mutate()
482β
483 await expect(vi.advanceTimersByTimeAsync(0)).rejects.toThrow(
484 'Expected mock error. All is well!',
485 )
486 })
487 })
488β
489 it('should throw when throwOnError is true', async () => {
490 const key = queryKey()
491 const err = new Error('Expected mock error. All is well!')
492 const { mutateAsync } = TestBed.runInInjectionContext(() => {
493 return injectMutation(() => ({
494 mutationKey: key,
495 mutationFn: () => {
496 return Promise.reject(err)
497 },
498 throwOnError: true,
499 }))
500 })
501β
502 await expect(() => mutateAsync()).rejects.toThrow(err)
503 })
504β
505 it('should throw when throwOnError function returns true', async () => {
506 const key = queryKey()
507 const err = new Error('Expected mock error. All is well!')
508 const { mutateAsync } = TestBed.runInInjectionContext(() => {
509 return injectMutation(() => ({
510 mutationKey: key,
511 mutationFn: () => {
512 return Promise.reject(err)
513 },
514 throwOnError: () => true,
515 }))
516 })
517β
518 await expect(() => mutateAsync()).rejects.toThrow(err)
519 })
520β
521 it('should resolve mutateAsync with the value returned from mutationFn', async () => {
522 const key = queryKey()
523 const { mutateAsync } = TestBed.runInInjectionContext(() => {
524 return injectMutation(() => ({
525 mutationKey: key,
526 mutationFn: (params: string) => sleep(10).then(() => params),
527 }))
528 })
529β
530 const promise = mutateAsync('Mock data')
531 await vi.advanceTimersByTimeAsync(11)
532β
533 await expect(promise).resolves.toBe('Mock data')
534 })
535β
536 describe('injection context', () => {
537 it('should throw NG0203 with descriptive error outside injection context', () => {
538 const key = queryKey()
539 expect(() => {
540 injectMutation(() => ({
541 mutationKey: key,
542 mutationFn: () => Promise.resolve(),
543 }))
544 }).toThrow(/NG0203(.*?)injectMutation/)
545 })
546β
547 it('should be usable outside injection context when passing an injector', () => {
548 const key = queryKey()
549 expect(() => {
550 injectMutation(
551 () => ({
552 mutationKey: key,
553 mutationFn: () => Promise.resolve(),
554 }),
555 {
556 injector: TestBed.inject(Injector),
557 },
558 )
559 }).not.toThrow()
560 })
561β
562 it('should complete mutation before whenStable() resolves', async () => {
563 const app = TestBed.inject(ApplicationRef)
564 let mutationStarted = false
565 let mutationCompleted = false
566β
567 const key = queryKey()
568 const mutation = TestBed.runInInjectionContext(() =>
569 injectMutation(() => ({
570 mutationKey: key,
571 mutationFn: async (data: string) => {
572 mutationStarted = true
573 await sleep(50)
574 mutationCompleted = true
575 return `processed: ${data}`
576 },
577 })),
578 )
579β
580 // Initial state
581 expect(mutation.data()).toBeUndefined()
582 expect(mutationStarted).toBe(false)
583β
584 // Start mutation
585 mutation.mutate('test')
586β
587 // Wait for mutation to start and Angular to be "stable"
588 const stablePromise = app.whenStable()
589 await vi.advanceTimersByTimeAsync(60)
590 await stablePromise
591β
592 // After whenStable(), mutation should be complete
593 expect(mutationStarted).toBe(true)
594 expect(mutationCompleted).toBe(true)
595 expect(mutation.isSuccess()).toBe(true)
596 expect(mutation.data()).toBe('processed: test')
597 })
598β
599 it('should handle synchronous mutation with retry', async () => {
600 const app = TestBed.inject(ApplicationRef)
601 let attemptCount = 0
602β
603 const mutation = TestBed.runInInjectionContext(() =>
604 injectMutation(() => ({
605 retry: 2,
606 retryDelay: 0, // No delay for synchronous retry
607 mutationFn: async (data: string) => {
608 attemptCount++
609 if (attemptCount <= 2) {
610 throw new Error(`Sync attempt ${attemptCount} failed`)
611 }
612 return `processed: ${data}`
613 },
614 })),
615 )
616β
617 // Start mutation
618 mutation.mutate('retry-test')
619β
620 // Synchronize pending effects for each retry attempt
621 TestBed.tick()
622 await Promise.resolve()
623 await vi.advanceTimersByTimeAsync(10)
624β
625 TestBed.tick()
626 await Promise.resolve()
627 await vi.advanceTimersByTimeAsync(10)
628β
629 TestBed.tick()
630β
631 const stablePromise = app.whenStable()
632 await Promise.resolve()
633 await vi.advanceTimersByTimeAsync(10)
634 await stablePromise
635β
636 expect(mutation.isSuccess()).toBe(true)
637 expect(mutation.data()).toBe('processed: retry-test')
638 expect(attemptCount).toBe(3) // Initial + 2 retries
639 })
640β
641 it('should handle multiple synchronous mutations on same key', async () => {
642 const app = TestBed.inject(ApplicationRef)
643 let callCount = 0
644β
645 const key = queryKey()
646β
647 const mutation1 = TestBed.runInInjectionContext(() =>
648 injectMutation(() => ({
649 mutationKey: key,
650 mutationFn: async (data: string) => {
651 callCount++
652 return `mutation1: ${data}`
653 },
654 })),
655 )
656β
657 const mutation2 = TestBed.runInInjectionContext(() =>
658 injectMutation(() => ({
659 mutationKey: key,
660 mutationFn: async (data: string) => {
661 callCount++
662 return `mutation2: ${data}`
663 },
664 })),
665 )
666β
667 // Start both mutations
668 mutation1.mutate('test1')
669 mutation2.mutate('test2')
670β
671 // Synchronize pending effects
672 TestBed.tick()
673β
674 const stablePromise = app.whenStable()
675 // Flush microtasks to allow TanStack Query's scheduled notifications to process
676 await Promise.resolve()
677 await vi.advanceTimersByTimeAsync(1)
678 await stablePromise
679β
680 expect(mutation1.isSuccess()).toBe(true)
681 expect(mutation1.data()).toBe('mutation1: test1')
682 expect(mutation2.isSuccess()).toBe(true)
683 expect(mutation2.data()).toBe('mutation2: test2')
684 expect(callCount).toBe(2)
685 })
686β
687 it('should handle synchronous mutation with optimistic updates', async () => {
688 const app = TestBed.inject(ApplicationRef)
689 const testQueryKey = queryKey()
690 let onMutateCalled = false
691 let onSuccessCalled = false
692β
693 // Set initial data
694 queryClient.setQueryData(testQueryKey, 'initial')
695β
696 const mutation = TestBed.runInInjectionContext(() =>
697 injectMutation(() => ({
698 mutationFn: async (data: string) => `final: ${data}`, // Synchronous resolution
699 onMutate: async (variables) => {
700 onMutateCalled = true
701 const previousData = queryClient.getQueryData(testQueryKey)
702 queryClient.setQueryData(testQueryKey, `optimistic: ${variables}`)
703 return { previousData }
704 },
705 onSuccess: (data) => {
706 onSuccessCalled = true
707 queryClient.setQueryData(testQueryKey, data)
708 },
709 })),
710 )
711β
712 // Start mutation
713 mutation.mutate('test')
714β
715 // Synchronize pending effects
716 TestBed.tick()
717β
718 const stablePromise = app.whenStable()
719 // Flush microtasks to allow TanStack Query's scheduled notifications to process
720 await Promise.resolve()
721 await vi.advanceTimersByTimeAsync(1)
722 await stablePromise
723β
724 expect(onMutateCalled).toBe(true)
725 expect(onSuccessCalled).toBe(true)
726 expect(mutation.isSuccess()).toBe(true)
727 expect(mutation.data()).toBe('final: test')
728 expect(queryClient.getQueryData(testQueryKey)).toBe('final: test')
729 })
730β
731 it('should handle synchronous mutation cancellation', async () => {
732 const app = TestBed.inject(ApplicationRef)
733β
734 const key = queryKey()
735 const mutation = TestBed.runInInjectionContext(() =>
736 injectMutation(() => ({
737 mutationKey: key,
738 mutationFn: async (data: string) => `processed: ${data}`, // Synchronous resolution
739 })),
740 )
741β
742 // Start mutation
743 mutation.mutate('test')
744β
745 // Synchronize pending effects
746 TestBed.tick()
747β
748 const stablePromise = app.whenStable()
749 // Flush microtasks to allow TanStack Query's scheduled notifications to process
750 await Promise.resolve()
751 await vi.advanceTimersByTimeAsync(1)
752 await stablePromise
753β
754 // Synchronous mutations complete immediately
755 expect(mutation.isSuccess()).toBe(true)
756 expect(mutation.data()).toBe('processed: test')
757 })
758 })
759})