File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
packages/react-query/src/__tests__ Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 11import { describe , expectTypeOf , it } from 'vitest'
2+ import { dataTagSymbol } from '@tanstack/query-core'
23import { mutationOptions } from '../mutationOptions'
34
45describe ( 'mutationOptions' , ( ) => {
@@ -20,4 +21,31 @@ describe('mutationOptions', () => {
2021 } ,
2122 } )
2223 } )
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+ } )
2351} )
You can’t perform that action at this time.
0 commit comments