@@ -2,97 +2,99 @@ import { describe, expectTypeOf, it } from 'vitest'
22import { queryOptions , useQuery } from '../index'
33
44describe ( 'useQuery' , ( ) => {
5- describe ( 'Config object overload' , ( ) => {
6- it ( 'TData should always be defined when initialData is provided as an object' , ( ) => {
7- const { data } = useQuery ( ( ) => ( {
8- queryKey : [ 'key' ] ,
9- queryFn : ( ) => ( { wow : true } ) ,
10- initialData : { wow : true } ,
11- } ) )
12-
13- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
14- } )
15-
16- it ( 'TData should be defined when passed through queryOptions' , ( ) => {
17- const options = queryOptions ( {
18- queryKey : [ 'key' ] ,
19- queryFn : ( ) => ( { wow : true } ) ,
20- initialData : { wow : true } ,
5+ describe ( 'initialData' , ( ) => {
6+ describe ( 'Config object overload' , ( ) => {
7+ it ( 'TData should always be defined when initialData is provided as an object' , ( ) => {
8+ const { data } = useQuery ( ( ) => ( {
9+ queryKey : [ 'key' ] ,
10+ queryFn : ( ) => ( { wow : true } ) ,
11+ initialData : { wow : true } ,
12+ } ) )
13+
14+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
2115 } )
22- const { data } = useQuery ( ( ) => options )
2316
24- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
25- } )
17+ it ( 'TData should be defined when passed through queryOptions' , ( ) => {
18+ const options = queryOptions ( {
19+ queryKey : [ 'key' ] ,
20+ queryFn : ( ) => ( { wow : true } ) ,
21+ initialData : { wow : true } ,
22+ } )
23+ const { data } = useQuery ( ( ) => options )
2624
27- it ( 'TData should always be defined when initialData is provided as a function which ALWAYS returns the data' , ( ) => {
28- const { data } = useQuery ( ( ) => ( {
29- queryKey : [ 'key' ] ,
30- queryFn : ( ) => ( { wow : true } ) ,
31- initialData : ( ) => ( { wow : true } ) ,
32- } ) )
25+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
26+ } )
3327
34- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
35- } )
28+ it ( 'TData should always be defined when initialData is provided as a function which ALWAYS returns the data' , ( ) => {
29+ const { data } = useQuery ( ( ) => ( {
30+ queryKey : [ 'key' ] ,
31+ queryFn : ( ) => ( { wow : true } ) ,
32+ initialData : ( ) => ( { wow : true } ) ,
33+ } ) )
3634
37- it ( 'TData should have undefined in the union when initialData is NOT provided' , ( ) => {
38- const { data } = useQuery ( ( ) => ( {
39- queryKey : [ 'key' ] ,
40- queryFn : ( ) => ( { wow : true } ) ,
41- } ) )
35+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
36+ } )
4237
43- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } | undefined > ( )
44- } )
38+ it ( 'TData should have undefined in the union when initialData is NOT provided' , ( ) => {
39+ const { data } = useQuery ( ( ) => ( {
40+ queryKey : [ 'key' ] ,
41+ queryFn : ( ) => ( { wow : true } ) ,
42+ } ) )
43+
44+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } | undefined > ( )
45+ } )
4546
46- it ( 'TData should have undefined in the union when initialData is provided as a function which can return undefined' , ( ) => {
47- const { data } = useQuery ( ( ) => ( {
48- queryKey : [ 'key' ] ,
49- queryFn : ( ) => ( { wow : true } ) ,
50- initialData : ( ) => undefined as { wow : boolean } | undefined ,
51- } ) )
47+ it ( 'TData should have undefined in the union when initialData is provided as a function which can return undefined' , ( ) => {
48+ const { data } = useQuery ( ( ) => ( {
49+ queryKey : [ 'key' ] ,
50+ queryFn : ( ) => ( { wow : true } ) ,
51+ initialData : ( ) => undefined as { wow : boolean } | undefined ,
52+ } ) )
5253
53- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } | undefined > ( )
54+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } | undefined > ( )
55+ } )
5456 } )
55- } )
5657
57- describe ( 'Query key overload' , ( ) => {
58- it ( 'TData should always be defined when initialData is provided' , ( ) => {
59- const { data } = useQuery ( ( ) => ( {
60- queryKey : [ 'key' ] ,
61- queryFn : ( ) => ( { wow : true } ) ,
62- initialData : { wow : true } ,
63- } ) )
58+ describe ( 'Query key overload' , ( ) => {
59+ it ( 'TData should always be defined when initialData is provided' , ( ) => {
60+ const { data } = useQuery ( ( ) => ( {
61+ queryKey : [ 'key' ] ,
62+ queryFn : ( ) => ( { wow : true } ) ,
63+ initialData : { wow : true } ,
64+ } ) )
6465
65- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
66- } )
66+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
67+ } )
6768
68- it ( 'TData should have undefined in the union when initialData is NOT provided' , ( ) => {
69- const { data } = useQuery ( ( ) => ( {
70- queryKey : [ 'key' ] ,
71- queryFn : ( ) => ( { wow : true } ) ,
72- } ) )
69+ it ( 'TData should have undefined in the union when initialData is NOT provided' , ( ) => {
70+ const { data } = useQuery ( ( ) => ( {
71+ queryKey : [ 'key' ] ,
72+ queryFn : ( ) => ( { wow : true } ) ,
73+ } ) )
7374
74- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } | undefined > ( )
75+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } | undefined > ( )
76+ } )
7577 } )
76- } )
7778
78- describe ( 'Query key and func' , ( ) => {
79- it ( 'TData should always be defined when initialData is provided' , ( ) => {
80- const { data } = useQuery ( ( ) => ( {
81- queryKey : [ 'key' ] ,
82- queryFn : ( ) => ( { wow : true } ) ,
83- initialData : { wow : true } ,
84- } ) )
79+ describe ( 'Query key and func' , ( ) => {
80+ it ( 'TData should always be defined when initialData is provided' , ( ) => {
81+ const { data } = useQuery ( ( ) => ( {
82+ queryKey : [ 'key' ] ,
83+ queryFn : ( ) => ( { wow : true } ) ,
84+ initialData : { wow : true } ,
85+ } ) )
8586
86- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
87- } )
87+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } > ( )
88+ } )
8889
89- it ( 'TData should have undefined in the union when initialData is NOT provided' , ( ) => {
90- const { data } = useQuery ( ( ) => ( {
91- queryKey : [ 'key' ] ,
92- queryFn : ( ) => ( { wow : true } ) ,
93- } ) )
90+ it ( 'TData should have undefined in the union when initialData is NOT provided' , ( ) => {
91+ const { data } = useQuery ( ( ) => ( {
92+ queryKey : [ 'key' ] ,
93+ queryFn : ( ) => ( { wow : true } ) ,
94+ } ) )
9495
95- expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } | undefined > ( )
96+ expectTypeOf ( data ) . toEqualTypeOf < { wow : boolean } | undefined > ( )
97+ } )
9698 } )
9799 } )
98100} )
0 commit comments