File tree Expand file tree Collapse file tree
packages/query-core/src/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -747,6 +747,40 @@ describe('queryObserver', () => {
747747 expect ( count ) . toBe ( 2 )
748748 } )
749749
750+ it ( 'should refetch at the interval returned when refetchInterval is a function' , async ( ) => {
751+ const key = queryKey ( )
752+ let count = 0
753+ const observer = new QueryObserver ( queryClient , {
754+ queryKey : key ,
755+ queryFn : ( ) => {
756+ count ++
757+ return Promise . resolve ( 'data' )
758+ } ,
759+ refetchInterval : ( ) => 10 ,
760+ } )
761+ const unsubscribe = observer . subscribe ( ( ) => undefined )
762+ expect ( count ) . toBe ( 1 )
763+ await vi . advanceTimersByTimeAsync ( 10 )
764+ expect ( count ) . toBe ( 2 )
765+ unsubscribe ( )
766+ } )
767+
768+ it ( 'should call refetchInterval with the query when it is a function' , async ( ) => {
769+ const key = queryKey ( )
770+ const refetchInterval = vi . fn ( ( ) => 10 )
771+ const observer = new QueryObserver ( queryClient , {
772+ queryKey : key ,
773+ queryFn : ( ) => sleep ( 10 ) . then ( ( ) => 'data' ) ,
774+ refetchInterval,
775+ } )
776+ const unsubscribe = observer . subscribe ( ( ) => undefined )
777+ await vi . advanceTimersByTimeAsync ( 10 )
778+ expect ( refetchInterval ) . toHaveBeenCalledWith (
779+ queryClient . getQueryCache ( ) . find ( { queryKey : key } ) ,
780+ )
781+ unsubscribe ( )
782+ } )
783+
750784 it ( 'should notify listeners when notifyOnChangeProps is a function returning props that changed' , async ( ) => {
751785 const key = queryKey ( )
752786
You can’t perform that action at this time.
0 commit comments