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?.options.mutationKey).toStrictEqual(['fake', 'value'])
386 })
387β
388 it('should update options on required signal input change', async () => {
389 const mutationCache = queryClient.getMutationCache()
390β
391 @Component({
392 selector: 'app-fake',
393 template: `
394 <button (click)="mutate()"></button>
395 <span>{{ mutation.data() }}</span>
396 `,
397 })
398 class FakeComponent {
399 name = input.required<string>()
400β
401 mutation = injectMutation(() => ({
402 mutationKey: ['fake', this.name()],
403 mutationFn: () => sleep(10).then(() => this.name()),
404 }))
405β
406 mutate(): void {
407 this.mutation.mutate()
408 }
409 }
410β
411 const fixture = TestBed.createComponent(FakeComponent)
412 const { debugElement } = fixture
413 setFixtureSignalInputs(fixture, { name: 'value' })
414β
415 const button = debugElement.query(By.css('button'))
416 const span = debugElement.query(By.css('span'))
417β
418 button.triggerEventHandler('click')
419 await vi.advanceTimersByTimeAsync(11)
420 fixture.detectChanges()
421β
422 expect(span.nativeElement.textContent).toEqual('value')
423β
424 setFixtureSignalInputs(fixture, { name: 'updatedValue' })
425β
426 button.triggerEventHandler('click')
427 await vi.advanceTimersByTimeAsync(11)
428 fixture.detectChanges()
429β
430 expect(span.nativeElement.textContent).toEqual('updatedValue')
431β
432 const mutations = mutationCache.findAll()
433 expect(mutations.length).toBe(2)
434 const [mutation1, mutation2] = mutations
435 expect(mutation1!.options.mutationKey).toEqual(['fake', 'value'])
436 expect(mutation2!.options.mutationKey).toEqual(['fake', 'updatedValue'])
437 })
438β
439 describe('throwOnError', () => {
440 it('should evaluate throwOnError when mutation is expected to throw', async () => {
441 const key = queryKey()
442 const err = new Error('Expected mock error. All is well!')
443 const boundaryFn = vi.fn()
444 const { mutate } = TestBed.runInInjectionContext(() => {
445 return injectMutation(() => ({
446 mutationKey: key,
447 mutationFn: () => {
448 return Promise.reject(err)
449 },
450 throwOnError: boundaryFn,
451 }))
452 })
453β
454 TestBed.tick()
455β
456 mutate()
457β
458 await vi.advanceTimersByTimeAsync(0)
459β
460 expect(boundaryFn).toHaveBeenCalledTimes(1)
461 expect(boundaryFn).toHaveBeenCalledWith(err)
462 })
463β
464 it('should throw when throwOnError is true and mutate is used', async () => {
465 const key = queryKey()
466 const { mutate } = TestBed.runInInjectionContext(() => {
467 return injectMutation(() => ({
468 mutationKey: key,
469 mutationFn: () => {
470 return Promise.reject(
471 new Error('Expected mock error. All is well!'),
472 )
473 },
474 throwOnError: true,
475 }))
476 })
477β
478 TestBed.tick()
479β
480 mutate()
481β
482 await expect(vi.advanceTimersByTimeAsync(0)).rejects.toThrow(
483 'Expected mock error. All is well!',
484 )
485 })
486 })
487β
488 it('should throw when throwOnError is true', async () => {
489 const key = queryKey()
490 const err = new Error('Expected mock error. All is well!')
491 const { mutateAsync } = TestBed.runInInjectionContext(() => {
492 return injectMutation(() => ({
493 mutationKey: key,
494 mutationFn: () => {
495 return Promise.reject(err)
496 },
497 throwOnError: true,
498 }))
499 })
500β
501 await expect(() => mutateAsync()).rejects.toThrow(err)
502 })
503β
504 it('should throw when throwOnError function returns true', async () => {
505 const key = queryKey()
506 const err = new Error('Expected mock error. All is well!')
507 const { mutateAsync } = TestBed.runInInjectionContext(() => {
508 return injectMutation(() => ({
509 mutationKey: key,
510 mutationFn: () => {
511 return Promise.reject(err)
512 },
513 throwOnError: () => true,
514 }))
515 })
516β
517 await expect(() => mutateAsync()).rejects.toThrow(err)
518 })
519β
520 it('should resolve mutateAsync with the value returned from mutationFn', async () => {
521 const key = queryKey()
522 const { mutateAsync } = TestBed.runInInjectionContext(() => {
523 return injectMutation(() => ({
524 mutationKey: key,
525 mutationFn: (params: string) => sleep(10).then(() => params),
526 }))
527 })
528β
529 const promise = mutateAsync('Mock data')
530 await vi.advanceTimersByTimeAsync(11)
531β
532 await expect(promise).resolves.toBe('Mock data')
533 })
534β
535 describe('injection context', () => {
536 it('should throw NG0203 with descriptive error outside injection context', () => {
537 const key = queryKey()
538 expect(() => {
539 injectMutation(() => ({
540 mutationKey: key,
541 mutationFn: () => Promise.resolve(),
542 }))
543 }).toThrow(/NG0203(.*?)injectMutation/)
544 })
545β
546 it('should be usable outside injection context when passing an injector', () => {
547 const key = queryKey()
548 expect(() => {
549 injectMutation(
550 () => ({
551 mutationKey: key,
552 mutationFn: () => Promise.resolve(),
553 }),
554 {
555 injector: TestBed.inject(Injector),
556 },
557 )
558 }).not.toThrow()
559 })
560β
561 it('should complete mutation before whenStable() resolves', async () => {
562 const app = TestBed.inject(ApplicationRef)
563 let mutationStarted = false
564 let mutationCompleted = false
565β
566 const key = queryKey()
567 const mutation = TestBed.runInInjectionContext(() =>
568 injectMutation(() => ({
569 mutationKey: key,
570 mutationFn: async (data: string) => {
571 mutationStarted = true
572 await sleep(50)
573 mutationCompleted = true
574 return `processed: ${data}`
575 },
576 })),
577 )
578β
579 // Initial state
580 expect(mutation.data()).toBeUndefined()
581 expect(mutationStarted).toBe(false)
582β
583 // Start mutation
584 mutation.mutate('test')
585β
586 // Wait for mutation to start and Angular to be "stable"
587 const stablePromise = app.whenStable()
588 await vi.advanceTimersByTimeAsync(60)
589 await stablePromise
590β
591 // After whenStable(), mutation should be complete
592 expect(mutationStarted).toBe(true)
593 expect(mutationCompleted).toBe(true)
594 expect(mutation.isSuccess()).toBe(true)
595 expect(mutation.data()).toBe('processed: test')
596 })
597β
598 it('should handle synchronous mutation with retry', async () => {
599 const app = TestBed.inject(ApplicationRef)
600 let attemptCount = 0
601β
602 const mutation = TestBed.runInInjectionContext(() =>
603 injectMutation(() => ({
604 retry: 2,
605 retryDelay: 0, // No delay for synchronous retry
606 mutationFn: async (data: string) => {
607 attemptCount++
608 if (attemptCount <= 2) {
609 throw new Error(`Sync attempt ${attemptCount} failed`)
610 }
611 return `processed: ${data}`
612 },
613 })),
614 )
615β
616 // Start mutation
617 mutation.mutate('retry-test')
618β
619 // Synchronize pending effects for each retry attempt
620 TestBed.tick()
621 await Promise.resolve()
622 await vi.advanceTimersByTimeAsync(10)
623β
624 TestBed.tick()
625 await Promise.resolve()
626 await vi.advanceTimersByTimeAsync(10)
627β
628 TestBed.tick()
629β
630 const stablePromise = app.whenStable()
631 await Promise.resolve()
632 await vi.advanceTimersByTimeAsync(10)
633 await stablePromise
634β
635 expect(mutation.isSuccess()).toBe(true)
636 expect(mutation.data()).toBe('processed: retry-test')
637 expect(attemptCount).toBe(3) // Initial + 2 retries
638 })
639β
640 it('should handle multiple synchronous mutations on same key', async () => {
641 const app = TestBed.inject(ApplicationRef)
642 let callCount = 0
643β
644 const key = queryKey()
645β
646 const mutation1 = TestBed.runInInjectionContext(() =>
647 injectMutation(() => ({
648 mutationKey: key,
649 mutationFn: async (data: string) => {
650 callCount++
651 return `mutation1: ${data}`
652 },
653 })),
654 )
655β
656 const mutation2 = TestBed.runInInjectionContext(() =>
657 injectMutation(() => ({
658 mutationKey: key,
659 mutationFn: async (data: string) => {
660 callCount++
661 return `mutation2: ${data}`
662 },
663 })),
664 )
665β
666 // Start both mutations
667 mutation1.mutate('test1')
668 mutation2.mutate('test2')
669β
670 // Synchronize pending effects
671 TestBed.tick()
672β
673 const stablePromise = app.whenStable()
674 // Flush microtasks to allow TanStack Query's scheduled notifications to process
675 await Promise.resolve()
676 await vi.advanceTimersByTimeAsync(1)
677 await stablePromise
678β
679 expect(mutation1.isSuccess()).toBe(true)
680 expect(mutation1.data()).toBe('mutation1: test1')
681 expect(mutation2.isSuccess()).toBe(true)
682 expect(mutation2.data()).toBe('mutation2: test2')
683 expect(callCount).toBe(2)
684 })
685β
686 it('should handle synchronous mutation with optimistic updates', async () => {
687 const app = TestBed.inject(ApplicationRef)
688 const testQueryKey = queryKey()
689 let onMutateCalled = false
690 let onSuccessCalled = false
691β
692 // Set initial data
693 queryClient.setQueryData(testQueryKey, 'initial')
694β
695 const mutation = TestBed.runInInjectionContext(() =>
696 injectMutation(() => ({
697 mutationFn: async (data: string) => `final: ${data}`, // Synchronous resolution
698 onMutate: async (variables) => {
699 onMutateCalled = true
700 const previousData = queryClient.getQueryData(testQueryKey)
701 queryClient.setQueryData(testQueryKey, `optimistic: ${variables}`)
702 return { previousData }
703 },
704 onSuccess: (data) => {
705 onSuccessCalled = true
706 queryClient.setQueryData(testQueryKey, data)
707 },
708 })),
709 )
710β
711 // Start mutation
712 mutation.mutate('test')
713β
714 // Synchronize pending effects
715 TestBed.tick()
716β
717 const stablePromise = app.whenStable()
718 // Flush microtasks to allow TanStack Query's scheduled notifications to process
719 await Promise.resolve()
720 await vi.advanceTimersByTimeAsync(1)
721 await stablePromise
722β
723 expect(onMutateCalled).toBe(true)
724 expect(onSuccessCalled).toBe(true)
725 expect(mutation.isSuccess()).toBe(true)
726 expect(mutation.data()).toBe('final: test')
727 expect(queryClient.getQueryData(testQueryKey)).toBe('final: test')
728 })
729β
730 it('should handle synchronous mutation cancellation', async () => {
731 const app = TestBed.inject(ApplicationRef)
732β
733 const key = queryKey()
734 const mutation = TestBed.runInInjectionContext(() =>
735 injectMutation(() => ({
736 mutationKey: key,
737 mutationFn: async (data: string) => `processed: ${data}`, // Synchronous resolution
738 })),
739 )
740β
741 // Start mutation
742 mutation.mutate('test')
743β
744 // Synchronize pending effects
745 TestBed.tick()
746β
747 const stablePromise = app.whenStable()
748 // Flush microtasks to allow TanStack Query's scheduled notifications to process
749 await Promise.resolve()
750 await vi.advanceTimersByTimeAsync(1)
751 await stablePromise
752β
753 // Synchronous mutations complete immediately
754 expect(mutation.isSuccess()).toBe(true)
755 expect(mutation.data()).toBe('processed: test')
756 })
757 })
758})