@@ -3,8 +3,9 @@ import { sleep } from '@tanstack/query-test-utils'
33import { injectQuery , queryOptions } from '..'
44import type { Signal } from '@angular/core'
55
6- describe ( 'initialData' , ( ) => {
7- describe ( 'Config object overload' , ( ) => {
6+ describe ( 'injectQuery' , ( ) => {
7+ describe ( 'initialData' , ( ) => {
8+ describe ( 'Config object overload' , ( ) => {
89 it ( 'TData should always be defined when initialData is provided as an object' , ( ) => {
910 const { data } = injectQuery ( ( ) => ( {
1011 queryKey : [ 'key' ] ,
@@ -107,73 +108,74 @@ describe('initialData', () => {
107108 } )
108109 } )
109110
110- describe ( 'structuralSharing' , ( ) => {
111- it ( 'should be able to use structuralSharing with unknown types' , ( ) => {
112- // https://github.com/TanStack/query/issues/6525#issuecomment-1938411343
113- injectQuery ( ( ) => ( {
114- queryKey : [ 'key' ] ,
115- queryFn : ( ) => 5 ,
116- structuralSharing : ( oldData , newData ) => {
117- expectTypeOf ( oldData ) . toBeUnknown ( )
118- expectTypeOf ( newData ) . toBeUnknown ( )
119- return newData
120- } ,
121- } ) )
111+ describe ( 'structuralSharing' , ( ) => {
112+ it ( 'should be able to use structuralSharing with unknown types' , ( ) => {
113+ // https://github.com/TanStack/query/issues/6525#issuecomment-1938411343
114+ injectQuery ( ( ) => ( {
115+ queryKey : [ 'key' ] ,
116+ queryFn : ( ) => 5 ,
117+ structuralSharing : ( oldData , newData ) => {
118+ expectTypeOf ( oldData ) . toBeUnknown ( )
119+ expectTypeOf ( newData ) . toBeUnknown ( )
120+ return newData
121+ } ,
122+ } ) )
123+ } )
122124 } )
123125 } )
124- } )
125126
126- describe ( 'Discriminated union return type' , ( ) => {
127- test ( 'data should be possibly undefined by default' , ( ) => {
128- const query = injectQuery ( ( ) => ( {
129- queryKey : [ 'key' ] ,
130- queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
131- } ) )
127+ describe ( 'Discriminated union return type' , ( ) => {
128+ test ( 'data should be possibly undefined by default' , ( ) => {
129+ const query = injectQuery ( ( ) => ( {
130+ queryKey : [ 'key' ] ,
131+ queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
132+ } ) )
132133
133- expectTypeOf ( query . data ) . toEqualTypeOf < Signal < string | undefined > > ( )
134- } )
134+ expectTypeOf ( query . data ) . toEqualTypeOf < Signal < string | undefined > > ( )
135+ } )
135136
136- test ( 'data should be defined when query is success' , ( ) => {
137- const query = injectQuery ( ( ) => ( {
138- queryKey : [ 'key' ] ,
139- queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
140- } ) )
137+ test ( 'data should be defined when query is success' , ( ) => {
138+ const query = injectQuery ( ( ) => ( {
139+ queryKey : [ 'key' ] ,
140+ queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
141+ } ) )
141142
142- if ( query . isSuccess ( ) ) {
143- expectTypeOf ( query . data ) . toEqualTypeOf < Signal < string > > ( )
144- }
145- } )
143+ if ( query . isSuccess ( ) ) {
144+ expectTypeOf ( query . data ) . toEqualTypeOf < Signal < string > > ( )
145+ }
146+ } )
146147
147- test ( 'error should be null when query is success' , ( ) => {
148- const query = injectQuery ( ( ) => ( {
149- queryKey : [ 'key' ] ,
150- queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
151- } ) )
148+ test ( 'error should be null when query is success' , ( ) => {
149+ const query = injectQuery ( ( ) => ( {
150+ queryKey : [ 'key' ] ,
151+ queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
152+ } ) )
152153
153- if ( query . isSuccess ( ) ) {
154- expectTypeOf ( query . error ) . toEqualTypeOf < Signal < null > > ( )
155- }
156- } )
154+ if ( query . isSuccess ( ) ) {
155+ expectTypeOf ( query . error ) . toEqualTypeOf < Signal < null > > ( )
156+ }
157+ } )
157158
158- test ( 'data should be undefined when query is pending' , ( ) => {
159- const query = injectQuery ( ( ) => ( {
160- queryKey : [ 'key' ] ,
161- queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
162- } ) )
159+ test ( 'data should be undefined when query is pending' , ( ) => {
160+ const query = injectQuery ( ( ) => ( {
161+ queryKey : [ 'key' ] ,
162+ queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
163+ } ) )
163164
164- if ( query . isPending ( ) ) {
165- expectTypeOf ( query . data ) . toEqualTypeOf < Signal < undefined > > ( )
166- }
167- } )
165+ if ( query . isPending ( ) ) {
166+ expectTypeOf ( query . data ) . toEqualTypeOf < Signal < undefined > > ( )
167+ }
168+ } )
168169
169- test ( 'error should be defined when query is error' , ( ) => {
170- const query = injectQuery ( ( ) => ( {
171- queryKey : [ 'key' ] ,
172- queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
173- } ) )
170+ test ( 'error should be defined when query is error' , ( ) => {
171+ const query = injectQuery ( ( ) => ( {
172+ queryKey : [ 'key' ] ,
173+ queryFn : ( ) => sleep ( 0 ) . then ( ( ) => 'Some data' ) ,
174+ } ) )
174175
175- if ( query . isError ( ) ) {
176- expectTypeOf ( query . error ) . toEqualTypeOf < Signal < Error > > ( )
177- }
176+ if ( query . isError ( ) ) {
177+ expectTypeOf ( query . error ) . toEqualTypeOf < Signal < Error > > ( )
178+ }
179+ } )
178180 } )
179181} )
0 commit comments