Open History to see the last commit
1import { describe, expectTypeOf, it } from 'vitest'
2β
3import { useMutationState } from '../useMutationState'
4import type {
5 Mutation,
6 MutationState,
7 MutationStatus,
8} from '@tanstack/query-core'
9β
10describe('useMutationState', () => {
11 it('should default to QueryState', () => {
12 const result = useMutationState({
13 filters: { status: 'pending' },
14 })
15β
16 expectTypeOf(result).toEqualTypeOf<
17 Array<MutationState<unknown, Error, unknown, unknown>>
18 >()
19 })
20β
21 it('should infer with select', () => {
22 const result = useMutationState({
23 filters: { status: 'pending' },
24 select: (mutation) => mutation.state.status,
25 })
26β
27 expectTypeOf(result).toEqualTypeOf<Array<MutationStatus>>()
28 })
29β
30 it('should propagate generics to select callback when TResult is typed MutationState', () => {
31 type MyData = { data: Array<string> }
32 type MyError = { code: number; message: string }
33 type MyVars = { id: number }
34β
35 useMutationState<MutationState<MyData, MyError, MyVars>>({
36 filters: { mutationKey: ['key'] },
37 select: (mutation) => {
38 expectTypeOf(mutation).toEqualTypeOf<
39 Mutation<MyData, MyError, MyVars, unknown>
40 >()
41 return mutation.state
42 },
43 })
44 })
45})