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

mutation-options.test-d.ts

33 lines989 Bytes

1import { assertType, describe, expectTypeOf, test } from 'vitest'
2import { mutationOptions } from '../mutation-options'
3​
4describe('mutationOptions', () => {
5 test('should not allow excess properties', () => {
6 assertType<Parameters<typeof mutationOptions>>([
7 {
8 mutationFn: () => Promise.resolve(5),
9 mutationKey: ['key'],
10 // @ts-expect-error this is a good error, because onMutates does not exist!
11 onMutates: 1000,
12 },
13 ])
14 assertType<Parameters<typeof mutationOptions>>([
15 {
16 mutationFn: () => Promise.resolve(5),
17 mutationKey: ['key'],
18 // @ts-expect-error this is a good error, because onMutates does not exist!
19 onMutates: 1000,
20 },
21 ])
22 })
23​
24 test('should infer types for callbacks', () => {
25 mutationOptions({
26 mutationFn: () => Promise.resolve(5),
27 mutationKey: ['key'],
28 onSuccess: (data) => {
29 expectTypeOf(data).toEqualTypeOf<number>()
30 },
31 })
32 })
33})