@@ -6,107 +6,107 @@ import type { Signal } from '@angular/core'
66describe ( 'injectQuery' , ( ) => {
77 describe ( 'initialData' , ( ) => {
88 describe ( 'Config object overload' , ( ) => {
9- it ( 'TData should always be defined when initialData is provided as an object' , ( ) => {
10- const { data } = injectQuery ( ( ) => ( {
11- queryKey : [ 'key' ] ,
12- queryFn : ( ) => ( { wow : true } ) ,
13- initialData : { wow : true } ,
14- } ) )
9+ it ( 'TData should always be defined when initialData is provided as an object' , ( ) => {
10+ const { data } = injectQuery ( ( ) => ( {
11+ queryKey : [ 'key' ] ,
12+ queryFn : ( ) => ( { wow : true } ) ,
13+ initialData : { wow : true } ,
14+ } ) )
1515
16- expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } > > ( )
17- } )
16+ expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } > > ( )
17+ } )
18+
19+ it ( 'TData should be defined when passed through queryOptions' , ( ) => {
20+ const options = ( ) =>
21+ queryOptions ( {
22+ queryKey : [ 'key' ] ,
23+ queryFn : ( ) => {
24+ return {
25+ wow : true ,
26+ }
27+ } ,
28+ initialData : {
29+ wow : true ,
30+ } ,
31+ } )
32+ const { data } = injectQuery ( options )
33+
34+ expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } > > ( )
35+ } )
1836
19- it ( 'TData should be defined when passed through queryOptions' , ( ) => {
20- const options = ( ) =>
21- queryOptions ( {
37+ it ( 'should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery' , ( ) => {
38+ const options = queryOptions ( {
39+ queryKey : [ 'key' ] ,
40+ queryFn : ( ) => Promise . resolve ( 1 ) ,
41+ } )
42+
43+ const query = injectQuery ( ( ) => ( {
44+ ...options ,
45+ select : ( data ) => data > 1 ,
46+ } ) )
47+
48+ expectTypeOf ( query . data ) . toEqualTypeOf < Signal < boolean | undefined > > ( )
49+ } )
50+
51+ it ( 'TData should always be defined when initialData is provided as a function which ALWAYS returns the data' , ( ) => {
52+ const { data } = injectQuery ( ( ) => ( {
2253 queryKey : [ 'key' ] ,
2354 queryFn : ( ) => {
2455 return {
2556 wow : true ,
2657 }
2758 } ,
28- initialData : {
59+ initialData : ( ) => ( {
2960 wow : true ,
30- } ,
31- } )
32- const { data } = injectQuery ( options )
33-
34- expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } > > ( )
35- } )
61+ } ) ,
62+ } ) )
3663
37- it ( 'should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery' , ( ) => {
38- const options = queryOptions ( {
39- queryKey : [ 'key' ] ,
40- queryFn : ( ) => Promise . resolve ( 1 ) ,
64+ expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } > > ( )
4165 } )
4266
43- const query = injectQuery ( ( ) => ( {
44- ...options ,
45- select : ( data ) => data > 1 ,
46- } ) )
47-
48- expectTypeOf ( query . data ) . toEqualTypeOf < Signal < boolean | undefined > > ( )
49- } )
50-
51- it ( 'TData should always be defined when initialData is provided as a function which ALWAYS returns the data' , ( ) => {
52- const { data } = injectQuery ( ( ) => ( {
53- queryKey : [ 'key' ] ,
54- queryFn : ( ) => {
55- return {
56- wow : true ,
57- }
58- } ,
59- initialData : ( ) => ( {
60- wow : true ,
61- } ) ,
62- } ) )
63-
64- expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } > > ( )
65- } )
66-
67- it ( 'TData should have undefined in the union when initialData is NOT provided' , ( ) => {
68- const { data } = injectQuery ( ( ) => ( {
69- queryKey : [ 'key' ] ,
70- queryFn : ( ) => {
71- return {
72- wow : true ,
73- }
74- } ,
75- } ) )
67+ it ( 'TData should have undefined in the union when initialData is NOT provided' , ( ) => {
68+ const { data } = injectQuery ( ( ) => ( {
69+ queryKey : [ 'key' ] ,
70+ queryFn : ( ) => {
71+ return {
72+ wow : true ,
73+ }
74+ } ,
75+ } ) )
7676
77- expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } | undefined > > ( )
78- } )
77+ expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } | undefined > > ( )
78+ } )
7979
80- it ( 'TData should have undefined in the union when initialData is provided as a function which can return undefined' , ( ) => {
81- const { data } = injectQuery ( ( ) => ( {
82- queryKey : [ 'key' ] ,
83- queryFn : ( ) => {
84- return {
85- wow : true ,
86- }
87- } ,
88- initialData : ( ) => undefined as { wow : boolean } | undefined ,
89- } ) )
80+ it ( 'TData should have undefined in the union when initialData is provided as a function which can return undefined' , ( ) => {
81+ const { data } = injectQuery ( ( ) => ( {
82+ queryKey : [ 'key' ] ,
83+ queryFn : ( ) => {
84+ return {
85+ wow : true ,
86+ }
87+ } ,
88+ initialData : ( ) => undefined as { wow : boolean } | undefined ,
89+ } ) )
9090
91- expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } | undefined > > ( )
92- } )
91+ expectTypeOf ( data ) . toEqualTypeOf < Signal < { wow : boolean } | undefined > > ( )
92+ } )
9393
94- it ( 'TData should be narrowed after an isSuccess check when initialData is provided as a function which can return undefined' , ( ) => {
95- const query = injectQuery ( ( ) => ( {
96- queryKey : [ 'key' ] ,
97- queryFn : ( ) => {
98- return {
99- wow : true ,
100- }
101- } ,
102- initialData : ( ) => undefined as { wow : boolean } | undefined ,
103- } ) )
94+ it ( 'TData should be narrowed after an isSuccess check when initialData is provided as a function which can return undefined' , ( ) => {
95+ const query = injectQuery ( ( ) => ( {
96+ queryKey : [ 'key' ] ,
97+ queryFn : ( ) => {
98+ return {
99+ wow : true ,
100+ }
101+ } ,
102+ initialData : ( ) => undefined as { wow : boolean } | undefined ,
103+ } ) )
104104
105- if ( query . isSuccess ( ) ) {
106- expectTypeOf ( query . data ) . toEqualTypeOf < Signal < { wow : boolean } > > ( )
107- }
105+ if ( query . isSuccess ( ) ) {
106+ expectTypeOf ( query . data ) . toEqualTypeOf < Signal < { wow : boolean } > > ( )
107+ }
108+ } )
108109 } )
109- } )
110110
111111 describe ( 'structuralSharing' , ( ) => {
112112 it ( 'should be able to use structuralSharing with unknown types' , ( ) => {
0 commit comments