1
1
import { afterEach , beforeEach , describe , expectTypeOf , it } from 'vitest'
2
2
import { QueryObserver } from '..'
3
3
import { createQueryClient , queryKey } from './utils'
4
- import type { QueryClient } from '..'
4
+ import type { DefaultError , QueryClient } from '..'
5
5
6
6
describe ( 'queryObserver' , ( ) => {
7
7
let queryClient : QueryClient
@@ -26,31 +26,58 @@ describe('queryObserver', () => {
26
26
if ( result . isPending ) {
27
27
expectTypeOf ( result . data ) . toEqualTypeOf < undefined > ( )
28
28
expectTypeOf ( result . error ) . toEqualTypeOf < null > ( )
29
+ expectTypeOf ( result . isError ) . toEqualTypeOf < false > ( )
30
+ expectTypeOf ( result . isPending ) . toEqualTypeOf < true > ( )
29
31
expectTypeOf ( result . isLoading ) . toEqualTypeOf < boolean > ( )
32
+ expectTypeOf ( result . isLoadingError ) . toEqualTypeOf < false > ( )
33
+ expectTypeOf ( result . isRefetchError ) . toEqualTypeOf < false > ( )
30
34
expectTypeOf ( result . status ) . toEqualTypeOf < 'pending' > ( )
31
35
}
32
36
if ( result . isLoading ) {
33
37
expectTypeOf ( result . data ) . toEqualTypeOf < undefined > ( )
34
38
expectTypeOf ( result . error ) . toEqualTypeOf < null > ( )
39
+ expectTypeOf ( result . isError ) . toEqualTypeOf < false > ( )
35
40
expectTypeOf ( result . isPending ) . toEqualTypeOf < true > ( )
41
+ expectTypeOf ( result . isLoading ) . toEqualTypeOf < true > ( )
42
+ expectTypeOf ( result . isLoadingError ) . toEqualTypeOf < false > ( )
43
+ expectTypeOf ( result . isRefetchError ) . toEqualTypeOf < false > ( )
44
+ expectTypeOf ( result . isSuccess ) . toEqualTypeOf < false > ( )
36
45
expectTypeOf ( result . status ) . toEqualTypeOf < 'pending' > ( )
37
46
}
38
47
39
48
if ( result . isLoadingError ) {
40
49
expectTypeOf ( result . data ) . toEqualTypeOf < undefined > ( )
41
- expectTypeOf ( result . error ) . toEqualTypeOf < Error > ( )
50
+ expectTypeOf ( result . error ) . toEqualTypeOf < DefaultError > ( )
51
+ expectTypeOf ( result . isError ) . toEqualTypeOf < true > ( )
52
+ expectTypeOf ( result . isPending ) . toEqualTypeOf < false > ( )
53
+ expectTypeOf ( result . isLoading ) . toEqualTypeOf < false > ( )
54
+ expectTypeOf ( result . isLoadingError ) . toEqualTypeOf < true > ( )
55
+ expectTypeOf ( result . isRefetchError ) . toEqualTypeOf < false > ( )
56
+ expectTypeOf ( result . isSuccess ) . toEqualTypeOf < false > ( )
42
57
expectTypeOf ( result . status ) . toEqualTypeOf < 'error' > ( )
43
58
}
44
59
45
60
if ( result . isRefetchError ) {
46
61
expectTypeOf ( result . data ) . toEqualTypeOf < { value : string } > ( )
47
- expectTypeOf ( result . error ) . toEqualTypeOf < Error > ( )
62
+ expectTypeOf ( result . error ) . toEqualTypeOf < DefaultError > ( )
63
+ expectTypeOf ( result . isError ) . toEqualTypeOf < true > ( )
64
+ expectTypeOf ( result . isPending ) . toEqualTypeOf < false > ( )
65
+ expectTypeOf ( result . isLoading ) . toEqualTypeOf < false > ( )
66
+ expectTypeOf ( result . isLoadingError ) . toEqualTypeOf < false > ( )
67
+ expectTypeOf ( result . isRefetchError ) . toEqualTypeOf < true > ( )
68
+ expectTypeOf ( result . isSuccess ) . toEqualTypeOf < false > ( )
48
69
expectTypeOf ( result . status ) . toEqualTypeOf < 'error' > ( )
49
70
}
50
71
51
72
if ( result . isSuccess ) {
52
73
expectTypeOf ( result . data ) . toEqualTypeOf < { value : string } > ( )
53
74
expectTypeOf ( result . error ) . toEqualTypeOf < null > ( )
75
+ expectTypeOf ( result . isError ) . toEqualTypeOf < false > ( )
76
+ expectTypeOf ( result . isPending ) . toEqualTypeOf < false > ( )
77
+ expectTypeOf ( result . isLoading ) . toEqualTypeOf < false > ( )
78
+ expectTypeOf ( result . isLoadingError ) . toEqualTypeOf < false > ( )
79
+ expectTypeOf ( result . isRefetchError ) . toEqualTypeOf < false > ( )
80
+ expectTypeOf ( result . isSuccess ) . toEqualTypeOf < true > ( )
54
81
expectTypeOf ( result . status ) . toEqualTypeOf < 'success' > ( )
55
82
}
56
83
} )
0 commit comments