@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
2
2
import { waitFor } from '@testing-library/react'
3
3
import { MutationObserver } from '../mutationObserver'
4
4
import { createQueryClient , executeMutation , queryKey , sleep } from './utils'
5
- import type { QueryClient } from '..'
5
+ import type { MutationFunctionContext , QueryClient } from '..'
6
6
import type { MutationState } from '../mutation'
7
7
8
8
describe ( 'mutations' , ( ) => {
@@ -49,7 +49,30 @@ describe('mutations', () => {
49
49
)
50
50
51
51
expect ( fn ) . toHaveBeenCalledTimes ( 1 )
52
- expect ( fn ) . toHaveBeenCalledWith ( 'vars' )
52
+ expect ( fn ) . toHaveBeenCalledWith ( 'vars' , expect . anything ( ) )
53
+ } )
54
+
55
+ test ( 'should provide context to mutationFn' , async ( ) => {
56
+ const mutationKey = queryKey ( )
57
+ const vars = 'vars' as const
58
+ const meta = { a : 1 }
59
+ const mutationFn = vi
60
+ . fn < [ typeof vars , MutationFunctionContext ] , Promise < 'data' > > ( )
61
+ . mockResolvedValue ( 'data' )
62
+
63
+ const mutation = new MutationObserver ( queryClient , {
64
+ mutationKey,
65
+ mutationFn,
66
+ meta,
67
+ } )
68
+
69
+ await mutation . mutate ( vars )
70
+
71
+ expect ( mutationFn ) . toHaveBeenCalledTimes ( 1 )
72
+ const context = mutationFn . mock . calls [ 0 ] ! [ 1 ]
73
+ expect ( context ) . toBeDefined ( )
74
+ expect ( context . mutationKey ) . toEqual ( mutationKey )
75
+ expect ( context . meta ) . toEqual ( meta )
53
76
} )
54
77
55
78
test ( 'mutation should set correct success states' , async ( ) => {
0 commit comments