@@ -255,10 +255,12 @@ describe('useQuery', () => {
255255 } )
256256 ) ;
257257
258- // We should only receive the first list due to the WHERE clause
258+ // Wait for the first result to be emitted
259259 await vi . waitFor (
260260 ( ) => {
261261 expect ( result . current . data [ 0 ] ?. name ) . toEqual ( 'first' ) ;
262+ expect ( result . current . isFetching ) . false ;
263+ expect ( result . current . isLoading ) . false ;
262264 } ,
263265 { timeout : 500 , interval : 100 }
264266 ) ;
@@ -268,6 +270,7 @@ describe('useQuery', () => {
268270 expect (
269271 hookEvents . find ( ( event ) => event . parameters [ 0 ] == '' && event . hookResults . isLoading == false )
270272 ) . toBeUndefined ( ) ;
273+ // We should have an event where this was both loading and fetching
271274 expect (
272275 hookEvents . find (
273276 ( event ) =>
@@ -276,6 +279,15 @@ describe('useQuery', () => {
276279 event . hookResults . isFetching == true
277280 )
278281 ) . toBeDefined ( ) ;
282+ // We should not have any event where isLoading or isFetching is false without data being presented
283+ expect (
284+ hookEvents . find (
285+ ( event ) =>
286+ event . parameters [ 0 ] == 'first' &&
287+ ( event . hookResults . isLoading || event . hookResults . isFetching ) == false &&
288+ event . hookResults . data [ 0 ] ?. name != 'first'
289+ )
290+ ) . toBeUndefined ( ) ;
279291
280292 // Verify that the fetching status was correlated to the parameters
281293 const firstResultEvent = hookEvents . find ( ( event ) => event . hookResults . data . length == 1 ) ;
@@ -287,14 +299,13 @@ describe('useQuery', () => {
287299 queryObserver . iterateListeners ( ( l ) =>
288300 l . queryUpdated ?.( {
289301 sql : 'select this is a broken query' ,
290- params : [ 'first ' ]
302+ params : [ 'error ' ]
291303 } )
292304 ) ;
293305
294306 // wait for the error to have been found
295307 await vi . waitFor (
296308 ( ) => {
297- console . log ( result . current ) ;
298309 expect ( result . current . error ) . not . equal ( null ) ;
299310 expect ( result . current . isFetching ) . false ;
300311 } ,
@@ -305,6 +316,15 @@ describe('useQuery', () => {
305316 expect (
306317 hookEvents . find ( ( event ) => event . hookResults . error != null && event . hookResults . isFetching == true )
307318 ) . toBeUndefined ( ) ;
319+ // there should not be any results where the fetching status is false, but the error is not presented
320+ expect (
321+ hookEvents . find (
322+ ( event ) =>
323+ event . parameters [ 0 ] == 'error' &&
324+ event . hookResults . error == null &&
325+ ( event . hookResults . isFetching || event . hookResults . isLoading ) == false
326+ )
327+ ) . toBeUndefined ( ) ;
308328
309329 queryObserver . iterateListeners ( ( l ) =>
310330 l . queryUpdated ?.( {
@@ -318,6 +338,8 @@ describe('useQuery', () => {
318338 ( ) => {
319339 expect ( result . current . data [ 0 ] ?. name ) . toEqual ( 'second' ) ;
320340 expect ( result . current . error ) . null ;
341+ expect ( result . current . isFetching ) . false ;
342+ expect ( result . current . isLoading ) . false ;
321343 } ,
322344 { timeout : 500 , interval : 100 }
323345 ) ;
@@ -326,6 +348,15 @@ describe('useQuery', () => {
326348 expect ( secondFetchingEvent ) . toBeDefined ( ) ;
327349 // We should immediately report that we are fetching once we detect new params
328350 expect ( secondFetchingEvent ?. hookResults . isFetching ) . true ;
351+ // We should never have reported that fetching was false before the results were present
352+ expect (
353+ hookEvents . find (
354+ ( event ) =>
355+ event . parameters [ 0 ] == 'second' &&
356+ event . hookResults . data [ 0 ] ?. name != 'second' &&
357+ ( event . hookResults . isFetching == false || event . hookResults . isLoading == false )
358+ )
359+ ) ;
329360 } ) ;
330361
331362 it ( 'should execute compatible queries' , async ( ) => {
0 commit comments