@@ -64,7 +64,7 @@ describe('useQuery', () => {
64
64
// it should provide the result type in the configuration
65
65
useQuery ( {
66
66
queryKey : [ key ] ,
67
- queryFn : async ( ) => true ,
67
+ queryFn : ( ) => Promise . resolve ( true ) ,
68
68
} )
69
69
70
70
// it should be possible to specify a union type as result type
@@ -109,22 +109,20 @@ describe('useQuery', () => {
109
109
type MyData = number
110
110
type MyQueryKey = readonly [ 'my-data' , number ]
111
111
112
- const getMyDataArrayKey : QueryFunction < MyData , MyQueryKey > = async ( {
112
+ const getMyDataArrayKey : QueryFunction < MyData , MyQueryKey > = ( {
113
113
queryKey : [ , n ] ,
114
114
} ) => {
115
- return n + 42
115
+ return Promise . resolve ( n + 42 )
116
116
}
117
117
118
118
useQuery ( {
119
119
queryKey : [ 'my-data' , 100 ] ,
120
120
queryFn : getMyDataArrayKey ,
121
121
} )
122
122
123
- const getMyDataStringKey : QueryFunction < MyData , [ '1' ] > = async (
124
- context ,
125
- ) => {
123
+ const getMyDataStringKey : QueryFunction < MyData , [ '1' ] > = ( context ) => {
126
124
expectTypeOf ( context . queryKey ) . toEqualTypeOf < [ '1' ] > ( )
127
- return Number ( context . queryKey [ 0 ] ) + 42
125
+ return Promise . resolve ( Number ( context . queryKey [ 0 ] ) + 42 )
128
126
}
129
127
130
128
useQuery ( {
@@ -161,7 +159,7 @@ describe('useQuery', () => {
161
159
queryFn : ( ) => fetcher ( qk [ 1 ] , 'token' ) ,
162
160
...options ,
163
161
} )
164
- const testQuery = useWrappedQuery ( [ '' ] , async ( ) => '1' )
162
+ const testQuery = useWrappedQuery ( [ '' ] , ( ) => Promise . resolve ( '1' ) )
165
163
expectTypeOf ( testQuery . data ) . toEqualTypeOf < string | undefined > ( )
166
164
167
165
// handles wrapped queries with custom fetcher passed directly to useQuery
@@ -178,7 +176,9 @@ describe('useQuery', () => {
178
176
'queryKey' | 'queryFn' | 'initialData'
179
177
> ,
180
178
) => useQuery ( { queryKey : qk , queryFn : fetcher , ...options } )
181
- const testFuncStyle = useWrappedFuncStyleQuery ( [ '' ] , async ( ) => true )
179
+ const testFuncStyle = useWrappedFuncStyleQuery ( [ '' ] , ( ) =>
180
+ Promise . resolve ( true ) ,
181
+ )
182
182
expectTypeOf ( testFuncStyle . data ) . toEqualTypeOf < boolean | undefined > ( )
183
183
}
184
184
} )
@@ -2487,7 +2487,7 @@ describe('useQuery', () => {
2487
2487
} )
2488
2488
2489
2489
// See https://github.com/tannerlinsley/react-query/issues/137
2490
- it ( 'should not override initial data in dependent queries' , async ( ) => {
2490
+ it ( 'should not override initial data in dependent queries' , ( ) => {
2491
2491
const key1 = queryKey ( )
2492
2492
const key2 = queryKey ( )
2493
2493
@@ -2524,7 +2524,7 @@ describe('useQuery', () => {
2524
2524
rendered . getByText ( 'Second Status: success' )
2525
2525
} )
2526
2526
2527
- it ( 'should update query options' , async ( ) => {
2527
+ it ( 'should update query options' , ( ) => {
2528
2528
const key = queryKey ( )
2529
2529
2530
2530
const queryFn = async ( ) => {
@@ -3777,12 +3777,12 @@ describe('useQuery', () => {
3777
3777
function Page ( ) {
3778
3778
const query = useQuery ( {
3779
3779
queryKey : key ,
3780
- queryFn : async ( ) => {
3780
+ queryFn : ( ) => {
3781
3781
if ( counter < 2 ) {
3782
3782
counter ++
3783
- throw new Error ( 'error' )
3783
+ return Promise . reject ( new Error ( 'error' ) )
3784
3784
} else {
3785
- return 'data'
3785
+ return Promise . resolve ( 'data' )
3786
3786
}
3787
3787
} ,
3788
3788
retryDelay : 10 ,
@@ -3955,9 +3955,11 @@ describe('useQuery', () => {
3955
3955
const [ filter , setFilter ] = React . useState ( '' )
3956
3956
const { data : todos } = useQuery ( {
3957
3957
queryKey : [ ...key , filter ] ,
3958
- queryFn : async ( ) => {
3959
- return ALL_TODOS . filter ( ( todo ) =>
3960
- filter ? todo . priority === filter : true ,
3958
+ queryFn : ( ) => {
3959
+ return Promise . resolve (
3960
+ ALL_TODOS . filter ( ( todo ) =>
3961
+ filter ? todo . priority === filter : true ,
3962
+ ) ,
3961
3963
)
3962
3964
} ,
3963
3965
initialData ( ) {
@@ -4047,7 +4049,7 @@ describe('useQuery', () => {
4047
4049
expect ( results [ 2 ] ) . toMatchObject ( { data : 'fetched data' , isStale : false } )
4048
4050
} )
4049
4051
4050
- it ( 'should support enabled:false in query object syntax' , async ( ) => {
4052
+ it ( 'should support enabled:false in query object syntax' , ( ) => {
4051
4053
const key = queryKey ( )
4052
4054
const queryFn = vi . fn < ( ...args : Array < unknown > ) => string > ( )
4053
4055
queryFn . mockImplementation ( ( ) => 'data' )
@@ -6025,7 +6027,7 @@ describe('useQuery', () => {
6025
6027
describe ( 'subscribed' , ( ) => {
6026
6028
it ( 'should be able to toggle subscribed' , async ( ) => {
6027
6029
const key = queryKey ( )
6028
- const queryFn = vi . fn ( async ( ) => 'data' )
6030
+ const queryFn = vi . fn ( ( ) => Promise . resolve ( 'data' ) )
6029
6031
function Page ( ) {
6030
6032
const [ subscribed , setSubscribed ] = React . useState ( true )
6031
6033
const { data } = useQuery ( {
@@ -6067,7 +6069,7 @@ describe('useQuery', () => {
6067
6069
6068
6070
it ( 'should not be attached to the query when subscribed is false' , async ( ) => {
6069
6071
const key = queryKey ( )
6070
- const queryFn = vi . fn ( async ( ) => 'data' )
6072
+ const queryFn = vi . fn ( ( ) => Promise . resolve ( 'data' ) )
6071
6073
function Page ( ) {
6072
6074
const { data } = useQuery ( {
6073
6075
queryKey : key ,
@@ -6097,7 +6099,7 @@ describe('useQuery', () => {
6097
6099
function Page ( ) {
6098
6100
const { data } = useQuery ( {
6099
6101
queryKey : key ,
6100
- queryFn : async ( ) => 'data' ,
6102
+ queryFn : ( ) => Promise . resolve ( 'data' ) ,
6101
6103
subscribed : false ,
6102
6104
} )
6103
6105
renders ++
@@ -6131,8 +6133,8 @@ describe('useQuery', () => {
6131
6133
const states : Array < UseQueryResult < unknown > > = [ ]
6132
6134
const error = new Error ( 'oops' )
6133
6135
6134
- const queryFn = async ( ) : Promise < unknown > => {
6135
- throw error
6136
+ const queryFn = ( ) : Promise < unknown > => {
6137
+ return Promise . reject ( error )
6136
6138
}
6137
6139
6138
6140
function Page ( ) {
@@ -6198,8 +6200,8 @@ describe('useQuery', () => {
6198
6200
function Page ( ) {
6199
6201
const { refetch, errorUpdateCount } = useQuery ( {
6200
6202
queryKey : key ,
6201
- queryFn : async ( ) : Promise < unknown > => {
6202
- throw error
6203
+ queryFn : ( ) : Promise < unknown > => {
6204
+ return Promise . reject ( error )
6203
6205
} ,
6204
6206
retry : false ,
6205
6207
} )
@@ -6517,7 +6519,7 @@ describe('useQuery', () => {
6517
6519
} )
6518
6520
6519
6521
// For Project without TS, when migrating from v4 to v5, make sure invalid calls due to bad parameters are tracked.
6520
- it ( 'should throw in case of bad arguments to enhance DevX' , async ( ) => {
6522
+ it ( 'should throw in case of bad arguments to enhance DevX' , ( ) => {
6521
6523
// Mock console error to avoid noise when test is run
6522
6524
const consoleMock = vi
6523
6525
. spyOn ( console , 'error' )
0 commit comments