@@ -62,6 +62,39 @@ describe('useQuery', () => {
6262 } )
6363 } )
6464
65+ test ( 'should work with options getter and be reactive' , async ( ) => {
66+ const keyRef = ref ( 'key011' )
67+ const resultRef = ref ( 'result02' )
68+ const query = useQuery ( ( ) => ( {
69+ queryKey : [ keyRef . value ] ,
70+ queryFn : ( ) => sleep ( 0 ) . then ( ( ) => resultRef . value ) ,
71+ } ) )
72+
73+ await vi . advanceTimersByTimeAsync ( 0 )
74+
75+ expect ( query ) . toMatchObject ( {
76+ status : { value : 'success' } ,
77+ data : { value : 'result02' } ,
78+ isPending : { value : false } ,
79+ isFetching : { value : false } ,
80+ isFetched : { value : true } ,
81+ isSuccess : { value : true } ,
82+ } )
83+
84+ resultRef . value = 'result021'
85+ keyRef . value = 'key012'
86+ await vi . advanceTimersByTimeAsync ( 0 )
87+
88+ expect ( query ) . toMatchObject ( {
89+ status : { value : 'success' } ,
90+ data : { value : 'result021' } ,
91+ isPending : { value : false } ,
92+ isFetching : { value : false } ,
93+ isFetched : { value : true } ,
94+ isSuccess : { value : true } ,
95+ } )
96+ } )
97+
6598 test ( 'should return pending status initially' , ( ) => {
6699 const query = useQuery ( {
67100 queryKey : [ 'key1' ] ,
@@ -274,7 +307,7 @@ describe('useQuery', () => {
274307 } )
275308
276309 test ( 'should use the current value for the queryKey when refetch is called' , async ( ) => {
277- const fetchFn = vi . fn ( )
310+ const fetchFn = vi . fn ( ( ) => 'foo' )
278311 const keyRef = ref ( 'key11' )
279312 const query = useQuery ( {
280313 queryKey : [ 'key10' , keyRef ] ,
@@ -302,7 +335,7 @@ describe('useQuery', () => {
302335 } )
303336
304337 test ( 'should be `enabled` to accept getter function' , async ( ) => {
305- const fetchFn = vi . fn ( )
338+ const fetchFn = vi . fn ( ( ) => 'foo' )
306339 const checked = ref ( false )
307340
308341 useQuery ( {
@@ -321,7 +354,7 @@ describe('useQuery', () => {
321354 } )
322355
323356 test ( 'should allow getters for query keys' , async ( ) => {
324- const fetchFn = vi . fn ( )
357+ const fetchFn = vi . fn ( ( ) => 'foo' )
325358 const key1 = ref ( 'key1' )
326359 const key2 = ref ( 'key2' )
327360
@@ -346,7 +379,7 @@ describe('useQuery', () => {
346379 } )
347380
348381 test ( 'should allow arbitrarily nested getters for query keys' , async ( ) => {
349- const fetchFn = vi . fn ( )
382+ const fetchFn = vi . fn ( ( ) => 'foo' )
350383 const key1 = ref ( 'key1' )
351384 const key2 = ref ( 'key2' )
352385 const key3 = ref ( 'key3' )
0 commit comments