-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathuseMutationState.test-d.tsx
More file actions
42 lines (38 loc) · 1.22 KB
/
useMutationState.test-d.tsx
File metadata and controls
42 lines (38 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { describe, expectTypeOf, it } from 'vitest'
import { useMutationState } from '../useMutationState'
import type {
Mutation,
MutationState,
MutationStatus,
} from '@tanstack/query-core'
describe('useMutationState', () => {
it('should default to QueryState', () => {
const result = useMutationState({
filters: { status: 'pending' },
})
expectTypeOf(result).toEqualTypeOf<
Array<MutationState<unknown, Error, unknown, unknown>>
>()
})
it('should infer with select', () => {
const result = useMutationState({
filters: { status: 'pending' },
select: (mutation) => mutation.state.status,
})
expectTypeOf(result).toEqualTypeOf<Array<MutationStatus>>()
})
it('should propagate generics to select callback when TResult is typed MutationState', () => {
type MyData = { data: Array<string> }
type MyError = { code: number; message: string }
type MyVars = { id: number }
useMutationState<MutationState<MyData, MyError, MyVars>>({
filters: { mutationKey: ['key'] },
select: (mutation) => {
expectTypeOf(mutation).toEqualTypeOf<
Mutation<MyData, MyError, MyVars, unknown>
>()
return mutation.state
},
})
})
})