Skip to content

Commit ff15e5d

Browse files
committed
test(react-query): add DataTag test case
1 parent 596896d commit ff15e5d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/react-query/src/__tests__/mutationOptions.test-d.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expectTypeOf, it } from 'vitest'
2+
import { dataTagSymbol } from '@tanstack/query-core'
23
import { mutationOptions } from '../mutationOptions'
34

45
describe('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
})

0 commit comments

Comments
 (0)