File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
packages/react-query/src/__tests__ Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -888,4 +888,35 @@ describe('useSuspenseQuery', () => {
888
888
)
889
889
consoleErrorSpy . mockRestore ( )
890
890
} )
891
+ it ( 'should properly refresh data when refetchInterval is set' , async ( ) => {
892
+ const key = queryKey ( )
893
+ let count = 0
894
+
895
+ function Page ( ) {
896
+ const state = useSuspenseQuery ( {
897
+ queryKey : key ,
898
+ queryFn : async ( ) => {
899
+ count ++
900
+ await sleep ( 1 )
901
+ return count
902
+ } ,
903
+ refetchInterval : 10 ,
904
+ } )
905
+
906
+ return < div > count: { state . data } </ div >
907
+ }
908
+
909
+ const rendered = renderWithClient (
910
+ queryClient ,
911
+ < React . Suspense fallback = "Loading..." >
912
+ < Page />
913
+ </ React . Suspense > ,
914
+ )
915
+
916
+ await waitFor ( ( ) => rendered . getByText ( 'count: 1' ) )
917
+ await waitFor ( ( ) => rendered . getByText ( 'count: 2' ) )
918
+ await waitFor ( ( ) => rendered . getByText ( 'count: 3' ) )
919
+
920
+ expect ( count ) . toBeGreaterThanOrEqual ( 3 )
921
+ } )
891
922
} )
You can’t perform that action at this time.
0 commit comments