/
useMutation.types.test.tsx
73 lines (63 loc) 路 1.89 KB
/
useMutation.types.test.tsx
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { reactive } from 'vue'
import { useMutation } from '../useMutation'
import { doNotExecute, Equal, Expect, successMutator } from './test-utils'
describe('Discriminated union return type', () => {
it('data should be possibly undefined by default', () => {
doNotExecute(() => {
const mutation = reactive(
useMutation({ mutationFn: successMutator<string> }),
)
const result: Expect<Equal<string | undefined, typeof mutation.data>> =
true
return result
})
})
it('data should be defined when mutation is success', () => {
doNotExecute(() => {
const mutation = reactive(
useMutation({ mutationFn: successMutator<string> }),
)
if (mutation.isSuccess) {
const result: Expect<Equal<string, typeof mutation.data>> = true
return result
}
return
})
})
it('error should be null when mutation is success', () => {
doNotExecute(() => {
const mutation = reactive(
useMutation({ mutationFn: successMutator<string> }),
)
if (mutation.isSuccess) {
const result: Expect<Equal<null, typeof mutation.error>> = true
return result
}
return
})
})
it('data should be undefined when mutation is loading', () => {
doNotExecute(() => {
const mutation = reactive(
useMutation({ mutationFn: successMutator<string> }),
)
if (mutation.isLoading) {
const result: Expect<Equal<undefined, typeof mutation.data>> = true
return result
}
return
})
})
it('error should be defined when mutation is error', () => {
doNotExecute(() => {
const mutation = reactive(
useMutation({ mutationFn: successMutator<string> }),
)
if (mutation.isError) {
const result: Expect<Equal<unknown, typeof mutation.error>> = true
return result
}
return
})
})
})