File tree 1 file changed +28
-0
lines changed
packages/react-query/src/__tests__
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { describe , expectTypeOf , it } from 'vitest'
2
+ import { dataTagSymbol } from '@tanstack/query-core'
2
3
import { mutationOptions } from '../mutationOptions'
3
4
4
5
describe ( 'mutationOptions' , ( ) => {
@@ -20,4 +21,31 @@ describe('mutationOptions', () => {
20
21
} ,
21
22
} )
22
23
} )
24
+
25
+ it ( 'should tag the mutationKey with the result type of the MutationFn' , ( ) => {
26
+ const { mutationKey } = mutationOptions ( {
27
+ mutationKey : [ 'key' ] ,
28
+ mutationFn : ( ) => Promise . resolve ( 5 ) ,
29
+ } )
30
+
31
+ expectTypeOf ( mutationKey [ dataTagSymbol ] ) . toEqualTypeOf < number > ( )
32
+ } )
33
+
34
+ it ( 'should tag the mutationKey with unknown if there is no mutationFn' , ( ) => {
35
+ const { mutationKey } = mutationOptions ( {
36
+ mutationKey : [ 'key' ] ,
37
+ } )
38
+
39
+ expectTypeOf ( mutationKey [ dataTagSymbol ] ) . toEqualTypeOf < unknown > ( )
40
+ } )
41
+
42
+ it ( 'should tag the mutationKey with the result type of the MutationFn if onSuccess is used' , ( ) => {
43
+ const { mutationKey } = mutationOptions ( {
44
+ mutationKey : [ 'key' ] ,
45
+ mutationFn : ( ) => Promise . resolve ( 5 ) ,
46
+ onSuccess : ( ) => { } ,
47
+ } )
48
+
49
+ expectTypeOf ( mutationKey [ dataTagSymbol ] ) . toEqualTypeOf < number > ( )
50
+ } )
23
51
} )
You can’t perform that action at this time.
0 commit comments