@@ -355,3 +355,136 @@ test('DevupQueryClient useInfiniteQuery with different HTTP methods', async () =
355355 } )
356356 }
357357} )
358+
359+ test ( 'DevupQueryClient useQueries with multiple queries' , async ( ) => {
360+ const api = createApi ( { baseUrl : 'https://api.example.com' } )
361+ const queryClient = new DevupQueryClient ( api )
362+
363+ const { result } = renderHook (
364+ ( ) =>
365+ queryClient . useQueries ( [
366+ [ 'get' , '/test1' ] ,
367+ [ 'get' , '/test2' ] ,
368+ ] ) ,
369+ { wrapper : createWrapper ( ) } ,
370+ )
371+
372+ await waitFor (
373+ ( ) => {
374+ expect ( result . current . every ( ( r ) => r . isSuccess ) ) . toBe ( true )
375+ } ,
376+ { timeout : 5000 } ,
377+ )
378+
379+ expect ( result . current ) . toHaveLength ( 2 )
380+ expect ( result . current [ 0 ] . data ) . toEqual ( { id : 1 , name : 'test' } )
381+ expect ( result . current [ 1 ] . data ) . toEqual ( { id : 1 , name : 'test' } )
382+ } )
383+
384+ test ( 'DevupQueryClient useQueries with options' , async ( ) => {
385+ const api = createApi ( { baseUrl : 'https://api.example.com' } )
386+ const queryClient = new DevupQueryClient ( api )
387+
388+ const { result } = renderHook (
389+ ( ) =>
390+ queryClient . useQueries ( [
391+ [ 'get' , '/test' as any , { params : { id : '123' } } ] ,
392+ ] ) ,
393+ { wrapper : createWrapper ( ) } ,
394+ )
395+
396+ await waitFor (
397+ ( ) => {
398+ expect ( result . current [ 0 ] . isSuccess ) . toBe ( true )
399+ } ,
400+ { timeout : 5000 } ,
401+ )
402+
403+ expect ( result . current [ 0 ] . data ) . toEqual ( { id : 1 , name : 'test' } )
404+ } )
405+
406+ test ( 'DevupQueryClient useQueries with combine' , async ( ) => {
407+ const api = createApi ( { baseUrl : 'https://api.example.com' } )
408+ const queryClient = new DevupQueryClient ( api )
409+
410+ const { result } = renderHook (
411+ ( ) =>
412+ queryClient . useQueries (
413+ [
414+ [ 'get' , '/test1' as any ] ,
415+ [ 'get' , '/test2' as any ] ,
416+ ] ,
417+ {
418+ combine : ( results ) => ( {
419+ data : results . map ( ( r ) => r . data ) ,
420+ pending : results . some ( ( r ) => r . isPending ) ,
421+ } ) ,
422+ } ,
423+ ) ,
424+ { wrapper : createWrapper ( ) } ,
425+ )
426+
427+ await waitFor (
428+ ( ) => {
429+ expect ( result . current . pending ) . toBe ( false )
430+ } ,
431+ { timeout : 5000 } ,
432+ )
433+
434+ expect ( result . current . data ) . toEqual ( [
435+ { id : 1 , name : 'test' } ,
436+ { id : 1 , name : 'test' } ,
437+ ] )
438+ } )
439+
440+ test ( 'DevupQueryClient useQueries with different HTTP methods' , async ( ) => {
441+ const api = createApi ( { baseUrl : 'https://api.example.com' } )
442+ const queryClient = new DevupQueryClient ( api )
443+
444+ const { result } = renderHook (
445+ ( ) =>
446+ queryClient . useQueries ( [
447+ [ 'get' , '/test' as any ] ,
448+ [ 'GET' , '/test' as any ] ,
449+ [ 'post' , '/test' as any ] ,
450+ ] ) ,
451+ { wrapper : createWrapper ( ) } ,
452+ )
453+
454+ await waitFor (
455+ ( ) => {
456+ expect ( result . current . every ( ( r ) => r . isSuccess ) ) . toBe ( true )
457+ } ,
458+ { timeout : 5000 } ,
459+ )
460+
461+ expect ( result . current ) . toHaveLength ( 3 )
462+ } )
463+
464+ test ( 'DevupQueryClient useQueries with queryOptions' , async ( ) => {
465+ const api = createApi ( { baseUrl : 'https://api.example.com' } )
466+ const queryClient = new DevupQueryClient ( api )
467+
468+ const { result } = renderHook (
469+ ( ) =>
470+ queryClient . useQueries ( [
471+ [ 'get' , '/test' as any , undefined , { staleTime : 1000 } ] ,
472+ [
473+ 'get' ,
474+ '/test2' as any ,
475+ { params : { id : '123' } } ,
476+ { staleTime : 2000 } ,
477+ ] ,
478+ ] ) ,
479+ { wrapper : createWrapper ( ) } ,
480+ )
481+
482+ await waitFor (
483+ ( ) => {
484+ expect ( result . current . every ( ( r ) => r . isSuccess ) ) . toBe ( true )
485+ } ,
486+ { timeout : 5000 } ,
487+ )
488+
489+ expect ( result . current ) . toHaveLength ( 2 )
490+ } )
0 commit comments