File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
packages/query-core/src/__tests__ Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -633,6 +633,32 @@ describe('queriesObserver', () => {
633633 trackResultSpy . mockRestore ( )
634634 } )
635635
636+ test ( 'should return cached combined result when nothing has changed' , ( ) => {
637+ const combine = vi . fn ( ( results : Array < QueryObserverResult > ) => ( {
638+ count : results . length ,
639+ } ) )
640+
641+ const key = queryKey ( )
642+ const queryFn = vi . fn ( ) . mockReturnValue ( 1 )
643+
644+ const queries = [ { queryKey : key , queryFn } ]
645+
646+ const observer = new QueriesObserver < { count : number } > (
647+ queryClient ,
648+ queries ,
649+ { combine } ,
650+ )
651+
652+ const [ raw1 , getCombined1 ] = observer . getOptimisticResult ( queries , combine )
653+ const combined1 = getCombined1 ( raw1 )
654+
655+ const [ raw2 , getCombined2 ] = observer . getOptimisticResult ( queries , combine )
656+ const combined2 = getCombined2 ( raw2 )
657+
658+ // Same combine, same queries → cached result returned
659+ expect ( combined1 ) . toBe ( combined2 )
660+ } )
661+
636662 test ( 'should track properties on all observers when trackResult is called' , ( ) => {
637663 const key1 = queryKey ( )
638664 const key2 = queryKey ( )
You can’t perform that action at this time.
0 commit comments