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

createMutation.svelte.test.ts

712 lines22.3 KB

1import { QueryClient, noop } from '@tanstack/query-core'
2import { createKey, sleep } from '@tanstack/query-test-utils'
3import { fireEvent, render } from '@testing-library/svelte'
4import { flushSync } from 'svelte'
5import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
6import { createMutation } from '../../src/index.js'
7import { withEffectRoot } from '../utils.svelte.js'
8import ConcurrentMutate from './ConcurrentMutate.svelte'
9import Failure from './Failure.svelte'
10import InvalidateFromContext from './InvalidateFromContext.svelte'
11import MutationFnContext from './MutationFnContext.svelte'
12import OptimisticUpdate from './OptimisticUpdate.svelte'
13import ParallelMutateAsync from './ParallelMutateAsync.svelte'
14import PerCallSuccess from './PerCallSuccess.svelte'
15import Reset from './Reset.svelte'
16import Success from './Success.svelte'
17import SuccessContext from './SuccessContext.svelte'
18import type { MutationFunctionContext } from '@tanstack/query-core'
19​
20describe('createMutation', () => {
21 let queryClient: QueryClient
22​
23 beforeEach(() => {
24 vi.useFakeTimers()
25 queryClient = new QueryClient()
26 })
27​
28 afterEach(() => {
29 queryClient.clear()
30 vi.useRealTimers()
31 })
32​
33 it('should be able to reset `error`', async () => {
34 const rendered = render(Reset, {
35 props: { queryClient },
36 })
37​
38 expect(rendered.getByText('Error: undefined')).toBeInTheDocument()
39​
40 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
41 await vi.advanceTimersByTimeAsync(11)
42 expect(rendered.getByText('Error: Expected mock error')).toBeInTheDocument()
43​
44 fireEvent.click(rendered.getByRole('button', { name: /Reset/i }))
45 await vi.advanceTimersByTimeAsync(0)
46 expect(rendered.getByText('Error: undefined')).toBeInTheDocument()
47 })
48​
49 it(
50 'should call mutate callbacks when createMutation has no callbacks',
51 withEffectRoot(async () => {
52 const callbacks: Array<string> = []
53​
54 const mutation = createMutation(
55 () => ({
56 mutationFn: (text: string) => sleep(10).then(() => text),
57 }),
58 () => queryClient,
59 )
60​
61 mutation.mutate('todo', {
62 onSuccess: () => callbacks.push('mutate.onSuccess'),
63 onSettled: () => callbacks.push('mutate.onSettled'),
64 })
65 await vi.advanceTimersByTimeAsync(10)
66 expect(callbacks).toStrictEqual(['mutate.onSuccess', 'mutate.onSettled'])
67 }),
68 )
69​
70 it(
71 'should call mutate error callbacks when createMutation has no callbacks',
72 withEffectRoot(async () => {
73 const callbacks: Array<string> = []
74​
75 const mutation = createMutation(
76 () => ({
77 mutationFn: (_text: string) =>
78 sleep(10).then(() => Promise.reject(new Error('oops'))),
79 }),
80 () => queryClient,
81 )
82​
83 mutation.mutate('todo', {
84 onError: () => callbacks.push('mutate.onError'),
85 onSettled: () => callbacks.push('mutate.onSettled'),
86 })
87 await vi.advanceTimersByTimeAsync(10)
88 expect(callbacks).toStrictEqual(['mutate.onError', 'mutate.onSettled'])
89 }),
90 )
91​
92 it(
93 'should call only mutate onSuccess when createMutation has no callbacks',
94 withEffectRoot(async () => {
95 const callbacks: Array<string> = []
96​
97 const mutation = createMutation(
98 () => ({
99 mutationFn: (text: string) => sleep(10).then(() => text),
100 }),
101 () => queryClient,
102 )
103​
104 mutation.mutate('todo', {
105 onSuccess: () => callbacks.push('mutate.onSuccess'),
106 })
107 await vi.advanceTimersByTimeAsync(10)
108 expect(callbacks).toStrictEqual(['mutate.onSuccess'])
109 }),
110 )
111​
112 it(
113 'should call only mutate onError when createMutation has no callbacks',
114 withEffectRoot(async () => {
115 const callbacks: Array<string> = []
116​
117 const mutation = createMutation(
118 () => ({
119 mutationFn: (_text: string) =>
120 sleep(10).then(() => Promise.reject(new Error('oops'))),
121 }),
122 () => queryClient,
123 )
124​
125 mutation.mutate('todo', {
126 onError: () => callbacks.push('mutate.onError'),
127 })
128 await vi.advanceTimersByTimeAsync(10)
129 expect(callbacks).toStrictEqual(['mutate.onError'])
130 }),
131 )
132​
133 it(
134 'should call only mutate onSettled when createMutation has no callbacks',
135 withEffectRoot(async () => {
136 const callbacks: Array<string> = []
137​
138 const mutation = createMutation(
139 () => ({
140 mutationFn: (text: string) => sleep(10).then(() => text),
141 }),
142 () => queryClient,
143 )
144​
145 mutation.mutate('todo', {
146 onSettled: () => callbacks.push('mutate.onSettled'),
147 })
148 await vi.advanceTimersByTimeAsync(10)
149 expect(callbacks).toStrictEqual(['mutate.onSettled'])
150 }),
151 )
152​
153 it(
154 'should call mutateAsync callbacks when createMutation has no callbacks',
155 withEffectRoot(async () => {
156 const callbacks: Array<string> = []
157​
158 const mutation = createMutation(
159 () => ({
160 mutationFn: (text: string) => sleep(10).then(() => text),
161 }),
162 () => queryClient,
163 )
164​
165 mutation.mutateAsync('todo', {
166 onSuccess: () => callbacks.push('mutateAsync.onSuccess'),
167 onSettled: () => callbacks.push('mutateAsync.onSettled'),
168 })
169 await vi.advanceTimersByTimeAsync(10)
170 expect(callbacks).toStrictEqual([
171 'mutateAsync.onSuccess',
172 'mutateAsync.onSettled',
173 ])
174 }),
175 )
176​
177 it(
178 'should call mutateAsync error callbacks when createMutation has no callbacks',
179 withEffectRoot(async () => {
180 const callbacks: Array<string> = []
181​
182 const mutation = createMutation(
183 () => ({
184 mutationFn: (_text: string) =>
185 sleep(10).then(() => Promise.reject(new Error('oops'))),
186 }),
187 () => queryClient,
188 )
189​
190 mutation
191 .mutateAsync('todo', {
192 onError: () => callbacks.push('mutateAsync.onError'),
193 onSettled: () => callbacks.push('mutateAsync.onSettled'),
194 })
195 .catch(noop)
196 await vi.advanceTimersByTimeAsync(10)
197 expect(callbacks).toStrictEqual([
198 'mutateAsync.onError',
199 'mutateAsync.onSettled',
200 ])
201 }),
202 )
203​
204 it(
205 'should call only mutateAsync onSuccess when createMutation has no callbacks',
206 withEffectRoot(async () => {
207 const callbacks: Array<string> = []
208​
209 const mutation = createMutation(
210 () => ({
211 mutationFn: (text: string) => sleep(10).then(() => text),
212 }),
213 () => queryClient,
214 )
215​
216 mutation.mutateAsync('todo', {
217 onSuccess: () => callbacks.push('mutateAsync.onSuccess'),
218 })
219 await vi.advanceTimersByTimeAsync(10)
220 expect(callbacks).toStrictEqual(['mutateAsync.onSuccess'])
221 }),
222 )
223​
224 it(
225 'should call only mutateAsync onError when createMutation has no callbacks',
226 withEffectRoot(async () => {
227 const callbacks: Array<string> = []
228​
229 const mutation = createMutation(
230 () => ({
231 mutationFn: (_text: string) =>
232 sleep(10).then(() => Promise.reject(new Error('oops'))),
233 }),
234 () => queryClient,
235 )
236​
237 mutation
238 .mutateAsync('todo', {
239 onError: () => callbacks.push('mutateAsync.onError'),
240 })
241 .catch(noop)
242 await vi.advanceTimersByTimeAsync(10)
243 expect(callbacks).toStrictEqual(['mutateAsync.onError'])
244 }),
245 )
246​
247 it(
248 'should call only mutateAsync onSettled when createMutation has no callbacks',
249 withEffectRoot(async () => {
250 const callbacks: Array<string> = []
251​
252 const mutation = createMutation(
253 () => ({
254 mutationFn: (text: string) => sleep(10).then(() => text),
255 }),
256 () => queryClient,
257 )
258​
259 mutation.mutateAsync('todo', {
260 onSettled: () => callbacks.push('mutateAsync.onSettled'),
261 })
262 await vi.advanceTimersByTimeAsync(10)
263 expect(callbacks).toStrictEqual(['mutateAsync.onSettled'])
264 }),
265 )
266​
267 it('should be able to call `onSuccess` and `onSettled` after each successful mutate', async () => {
268 const onSuccessMock = vi.fn<(data: number) => void>()
269 const onSettledMock = vi.fn<(data: number | undefined) => void>()
270​
271 const rendered = render(Success, {
272 props: {
273 queryClient,
274 onSuccessMock,
275 onSettledMock,
276 },
277 })
278​
279 expect(rendered.getByText('Count: 0')).toBeInTheDocument()
280​
281 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
282 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
283 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
284 await vi.advanceTimersByTimeAsync(10)
285 expect(rendered.getByText('Count: 3')).toBeInTheDocument()
286​
287 expect(onSuccessMock).toHaveBeenCalledTimes(3)
288 expect(onSuccessMock).toHaveBeenNthCalledWith(1, 1)
289 expect(onSuccessMock).toHaveBeenNthCalledWith(2, 2)
290 expect(onSuccessMock).toHaveBeenNthCalledWith(3, 3)
291​
292 expect(onSettledMock).toHaveBeenCalledTimes(3)
293 expect(onSettledMock).toHaveBeenNthCalledWith(1, 1)
294 expect(onSettledMock).toHaveBeenNthCalledWith(2, 2)
295 expect(onSettledMock).toHaveBeenNthCalledWith(3, 3)
296 })
297​
298 it('should set correct values for `failureReason` and `failureCount` on multiple mutate calls', async () => {
299 type Value = { count: number }
300​
301 const mutationFn = vi.fn<(value: Value) => Promise<Value>>()
302​
303 // oxlint-disable-next-line vitest/prefer-mock-return-shorthand -- the promise must be created when the mock is called, not when it is set up
304 mutationFn.mockImplementationOnce(() =>
305 sleep(20).then(() => Promise.reject(`Expected mock error`)),
306 )
307​
308 mutationFn.mockImplementation((value) => sleep(10).then(() => value))
309​
310 const rendered = render(Failure, {
311 props: {
312 queryClient,
313 mutationFn,
314 },
315 })
316​
317 expect(rendered.getByText('Data: undefined')).toBeInTheDocument()
318​
319 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
320 expect(rendered.getByText('Data: undefined')).toBeInTheDocument()
321 await vi.advanceTimersByTimeAsync(21)
322 expect(rendered.getByText('Status: error')).toBeInTheDocument()
323 expect(rendered.getByText('Failure Count: 1')).toBeInTheDocument()
324 expect(
325 rendered.getByText('Failure Reason: Expected mock error'),
326 ).toBeInTheDocument()
327​
328 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
329 await vi.advanceTimersByTimeAsync(0)
330 expect(rendered.getByText('Status: pending')).toBeInTheDocument()
331 await vi.advanceTimersByTimeAsync(11)
332 expect(rendered.getByText('Status: success')).toBeInTheDocument()
333 expect(rendered.getByText('Data: 2')).toBeInTheDocument()
334 expect(rendered.getByText('Failure Count: 0')).toBeInTheDocument()
335 expect(rendered.getByText('Failure Reason: undefined')).toBeInTheDocument()
336 })
337​
338 it(
339 'should be able to call `onSuccess` callback after successful mutateAsync',
340 withEffectRoot(async () => {
341 const callbacks: Array<string> = []
342​
343 const mutation = createMutation(
344 () => ({
345 mutationFn: (text: string) => sleep(10).then(() => text),
346 onSuccess: () => callbacks.push('useMutation.onSuccess'),
347 }),
348 () => queryClient,
349 )
350​
351 mutation.mutateAsync('todo', {
352 onSuccess: () => callbacks.push('mutateAsync.onSuccess'),
353 })
354 await vi.advanceTimersByTimeAsync(10)
355 expect(callbacks).toStrictEqual([
356 'useMutation.onSuccess',
357 'mutateAsync.onSuccess',
358 ])
359 }),
360 )
361​
362 it(
363 'should be able to call `onError` callback after failed mutateAsync',
364 withEffectRoot(async () => {
365 const callbacks: Array<string> = []
366​
367 const mutation = createMutation(
368 () => ({
369 mutationFn: (_text: string) =>
370 sleep(10).then(() => Promise.reject(new Error('oops'))),
371 onError: () => callbacks.push('useMutation.onError'),
372 }),
373 () => queryClient,
374 )
375​
376 mutation
377 .mutateAsync('todo', {
378 onError: () => callbacks.push('mutateAsync.onError'),
379 })
380 .catch(noop)
381 await vi.advanceTimersByTimeAsync(10)
382 expect(callbacks).toStrictEqual([
383 'useMutation.onError',
384 'mutateAsync.onError',
385 ])
386 }),
387 )
388​
389 it(
390 'should be able to call `onSettled` callback after mutateAsync',
391 withEffectRoot(async () => {
392 const callbacks: Array<string> = []
393​
394 const mutation = createMutation(
395 () => ({
396 mutationFn: (text: string) => sleep(10).then(() => text),
397 onSettled: () => callbacks.push('useMutation.onSettled'),
398 }),
399 () => queryClient,
400 )
401​
402 mutation.mutateAsync('todo', {
403 onSettled: () => callbacks.push('mutateAsync.onSettled'),
404 })
405 await vi.advanceTimersByTimeAsync(10)
406 expect(callbacks).toStrictEqual([
407 'useMutation.onSettled',
408 'mutateAsync.onSettled',
409 ])
410 }),
411 )
412​
413 it(
414 'should be able to override the useMutation success callbacks',
415 withEffectRoot(async () => {
416 const callbacks: Array<string> = []
417​
418 const mutation = createMutation(
419 () => ({
420 mutationFn: (text: string) => sleep(10).then(() => text),
421 onSuccess: () =>
422 sleep(10).then(() => callbacks.push('useMutation.onSuccess')),
423 onSettled: () =>
424 sleep(10).then(() => callbacks.push('useMutation.onSettled')),
425 }),
426 () => queryClient,
427 )
428​
429 mutation
430 .mutateAsync('todo', {
431 onSuccess: () => callbacks.push('mutateAsync.onSuccess'),
432 onSettled: () => callbacks.push('mutateAsync.onSettled'),
433 })
434 .then((result) => callbacks.push(`mutateAsync.result:${result}`))
435 await vi.advanceTimersByTimeAsync(30)
436 expect(callbacks).toStrictEqual([
437 'useMutation.onSuccess',
438 'useMutation.onSettled',
439 'mutateAsync.onSuccess',
440 'mutateAsync.onSettled',
441 'mutateAsync.result:todo',
442 ])
443 }),
444 )
445​
446 it(
447 'should be able to override the error callbacks when using mutateAsync',
448 withEffectRoot(async () => {
449 const callbacks: Array<string> = []
450​
451 const mutation = createMutation(
452 () => ({
453 mutationFn: (_text: string) =>
454 sleep(10).then(() => Promise.reject(new Error('oops'))),
455 onError: () =>
456 sleep(10).then(() => callbacks.push('useMutation.onError')),
457 onSettled: () =>
458 sleep(10).then(() => callbacks.push('useMutation.onSettled')),
459 }),
460 () => queryClient,
461 )
462​
463 mutation
464 .mutateAsync('todo', {
465 onError: () => callbacks.push('mutateAsync.onError'),
466 onSettled: () => callbacks.push('mutateAsync.onSettled'),
467 })
468 .catch((error) =>
469 callbacks.push(`mutateAsync.error:${(error as Error).message}`),
470 )
471 await vi.advanceTimersByTimeAsync(30)
472 expect(callbacks).toStrictEqual([
473 'useMutation.onError',
474 'useMutation.onSettled',
475 'mutateAsync.onError',
476 'mutateAsync.onSettled',
477 'mutateAsync.error:oops',
478 ])
479 }),
480 )
481​
482 it(
483 'should recreate observer when queryClient changes',
484 withEffectRoot(async () => {
485 const queryClient1 = new QueryClient()
486 const queryClient2 = new QueryClient()
487​
488 let activeClient = $state(queryClient1)
489​
490 const mutation = createMutation(
491 () => ({
492 mutationFn: (params: string) => sleep(10).then(() => params),
493 }),
494 () => activeClient,
495 )
496​
497 mutation.mutate('first')
498 await vi.advanceTimersByTimeAsync(11)
499 expect(mutation.status).toBe('success')
500 expect(mutation.data).toBe('first')
501​
502 activeClient = queryClient2
503 flushSync()
504 expect(mutation.status).toBe('idle')
505 expect(mutation.data).toBeUndefined()
506 }),
507 )
508​
509 it('should update the cache in onMutate and roll back via onMutateResult in onError', async () => {
510 const key = createKey()
511 queryClient.setQueryData<Array<string>>(key, ['Todo 1'])
512​
513 const rendered = render(OptimisticUpdate, {
514 props: { queryClient, queryKey: key, shouldSucceed: false },
515 })
516​
517 fireEvent.click(rendered.getByRole('button', { name: /add/i }))
518 // The optimistic value lands after onMutate's first await, so flush
519 // microtasks before asserting.
520 await vi.advanceTimersByTimeAsync(0)
521 expect(queryClient.getQueryData(key)).toStrictEqual(['Todo 1', 'Todo 2'])
522 await vi.advanceTimersByTimeAsync(10)
523 expect(queryClient.getQueryData(key)).toStrictEqual(['Todo 1'])
524 })
525​
526 it('should keep the optimistic update in place when the mutation succeeds', async () => {
527 const key = createKey()
528 queryClient.setQueryData<Array<string>>(key, ['Todo 1'])
529​
530 const rendered = render(OptimisticUpdate, {
531 props: { queryClient, queryKey: key, shouldSucceed: true },
532 })
533​
534 fireEvent.click(rendered.getByRole('button', { name: /add/i }))
535 await vi.advanceTimersByTimeAsync(10)
536 expect(queryClient.getQueryData(key)).toStrictEqual(['Todo 1', 'Todo 2'])
537 })
538​
539 it('should pass a non-undefined onMutateResult alongside context to onSuccess', async () => {
540 const onSuccessMock =
541 vi.fn<
542 (
543 data: string,
544 variables: string,
545 onMutateResult: { startedWith: string },
546 context: MutationFunctionContext,
547 ) => void
548 >()
549​
550 const rendered = render(SuccessContext, {
551 props: { queryClient, onSuccessMock },
552 })
553​
554 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
555 await vi.advanceTimersByTimeAsync(10)
556 expect(onSuccessMock).toHaveBeenCalledTimes(1)
557 const [data, variables, onMutateResult, context] =
558 onSuccessMock.mock.calls[0]!
559 expect(data).toBe('TODO')
560 expect(variables).toBe('todo')
561 expect(onMutateResult).toStrictEqual({ startedWith: 'todo' })
562 expect(context.client).toBe(queryClient)
563 expect(context.meta).toBeUndefined()
564 expect(context.mutationKey).toBeUndefined()
565 })
566​
567 it('should include mutationKey in the context passed to hook-level callbacks', async () => {
568 const onSuccessMock =
569 vi.fn<
570 (
571 data: string,
572 variables: string,
573 onMutateResult: { startedWith: string },
574 context: MutationFunctionContext,
575 ) => void
576 >()
577​
578 const rendered = render(SuccessContext, {
579 props: { queryClient, mutationKey: ['todos', 'add'], onSuccessMock },
580 })
581​
582 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
583 await vi.advanceTimersByTimeAsync(10)
584 expect(onSuccessMock).toHaveBeenCalledTimes(1)
585 expect(onSuccessMock.mock.calls[0]?.[3].mutationKey).toStrictEqual([
586 'todos',
587 'add',
588 ])
589 })
590​
591 it('should give mutationFn the same QueryClient instance via context', async () => {
592 const key = createKey()
593 queryClient.setQueryData(key, 'tag-from-this-client')
594​
595 const rendered = render(MutationFnContext, {
596 props: { queryClient, queryKey: key },
597 })
598​
599 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
600 await vi.advanceTimersByTimeAsync(11)
601 expect(rendered.getByText('data: tag-from-this-client')).toBeInTheDocument()
602 })
603​
604 it('should let onSuccess invalidate queries via context.client without a useQueryClient() closure', async () => {
605 const key = createKey()
606 queryClient.setQueryData(key, 'data')
607​
608 const rendered = render(InvalidateFromContext, {
609 props: { queryClient, queryKey: key },
610 })
611​
612 expect(queryClient.getQueryState(key)?.isInvalidated).toBe(false)
613​
614 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
615 await vi.advanceTimersByTimeAsync(10)
616 expect(queryClient.getQueryState(key)?.isInvalidated).toBe(true)
617 })
618​
619 it('should give a per-call onSuccess the same QueryClient instance via context', async () => {
620 const onSuccessMutate =
621 vi.fn<
622 (
623 data: string,
624 variables: string,
625 onMutateResult: unknown,
626 context: MutationFunctionContext,
627 ) => void
628 >()
629​
630 const rendered = render(PerCallSuccess, {
631 props: { queryClient, onSuccessMutate },
632 })
633​
634 fireEvent.click(rendered.getByRole('button', { name: /Mutate/i }))
635 await vi.advanceTimersByTimeAsync(10)
636 expect(onSuccessMutate).toHaveBeenCalledTimes(1)
637 expect(onSuccessMutate.mock.calls[0]?.[3].client).toBe(queryClient)
638 })
639​
640 it('should be able to run multiple mutateAsync calls in parallel with Promise.all', async () => {
641 const rendered = render(ParallelMutateAsync, {
642 props: { queryClient, strategy: 'all' },
643 })
644​
645 fireEvent.click(rendered.getByRole('button', { name: /upload all/i }))
646 await vi.advanceTimersByTimeAsync(10)
647 expect(
648 rendered.getByText(
649 'result: uploaded: file1, uploaded: file2, uploaded: file3',
650 ),
651 ).toBeInTheDocument()
652 })
653​
654 it('should handle Promise.all rejection when one parallel mutateAsync call fails', async () => {
655 const rendered = render(ParallelMutateAsync, {
656 props: { queryClient, strategy: 'all', failOn: 'file2' },
657 })
658​
659 fireEvent.click(rendered.getByRole('button', { name: /upload all/i }))
660 await vi.advanceTimersByTimeAsync(10)
661 expect(
662 rendered.getByText('result: error: upload failed'),
663 ).toBeInTheDocument()
664 })
665​
666 it('should handle partial failure in parallel mutateAsync calls with Promise.allSettled', async () => {
667 const rendered = render(ParallelMutateAsync, {
668 props: { queryClient, strategy: 'allSettled', failOn: 'file2' },
669 })
670​
671 fireEvent.click(rendered.getByRole('button', { name: /upload all/i }))
672 await vi.advanceTimersByTimeAsync(10)
673 expect(
674 rendered.getByText(
675 'result: uploaded: file1, error: upload failed, uploaded: file3',
676 ),
677 ).toBeInTheDocument()
678 })
679​
680 it('should only fire the per-call onSuccess for the last mutate() call', async () => {
681 const onSuccessMutate =
682 vi.fn<
683 (
684 data: string,
685 variables: string,
686 onMutateResult: unknown,
687 context: MutationFunctionContext,
688 ) => void
689 >()
690​
691 const rendered = render(ConcurrentMutate, {
692 props: { queryClient, onSuccessMutate },
693 })
694​
695 expect(rendered.getByText('data: null, status: idle')).toBeInTheDocument()
696​
697 fireEvent.click(rendered.getByRole('button', { name: /mutate1/i }))
698 fireEvent.click(rendered.getByRole('button', { name: /mutate2/i }))
699 await vi.advanceTimersByTimeAsync(11)
700 expect(
701 rendered.getByText('data: Todo 2, status: success'),
702 ).toBeInTheDocument()
703​
704 expect(onSuccessMutate).toHaveBeenCalledTimes(1)
705 expect(onSuccessMutate).toHaveBeenCalledWith(
706 'Todo 2',
707 'Todo 2',
708 undefined,
709 expect.anything(),
710 )
711 })
712})