Open History to see the last commit
1import { describe, expectTypeOf, it } from 'vitest'
2import { injectMutationState } from '..'
3import type { Mutation, MutationState, MutationStatus } from '..'
4β
5describe('injectMutationState', () => {
6 it('should default to QueryState', () => {
7 const result = injectMutationState(() => ({
8 filters: { status: 'pending' },
9 }))
10β
11 expectTypeOf(result()).toEqualTypeOf<Array<MutationState>>()
12 })
13β
14 it('should infer with select', () => {
15 const result = injectMutationState(() => ({
16 filters: { status: 'pending' },
17 select: (mutation) => mutation.state.status,
18 }))
19β
20 expectTypeOf(result()).toEqualTypeOf<Array<MutationStatus>>()
21 })
22β
23 it('should infer the mutation type from a mutation-state result', () => {
24 type Result = MutationState<
25 string,
26 Error,
27 { id: number },
28 { previous: string }
29 >
30β
31 injectMutationState<Result>(() => ({
32 select: (mutation) => {
33 expectTypeOf(mutation).toEqualTypeOf<
34 Mutation<string, Error, { id: number }, { previous: string }>
35 >()
36 return mutation.state
37 },
38 }))
39 })
40})