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