File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import {
1010 QueryErrorResetBoundary ,
1111 useQueryErrorResetBoundary ,
1212 UseQueryResult ,
13+ UseInfiniteQueryResult ,
14+ useInfiniteQuery ,
1315} from '../..'
1416
1517describe ( "useQuery's in Suspense mode" , ( ) => {
@@ -65,6 +67,39 @@ describe("useQuery's in Suspense mode", () => {
6567 expect ( states [ 1 ] ) . toMatchObject ( { data : 2 , status : 'success' } )
6668 } )
6769
70+ it ( 'should return the correct states for a successful infinite query' , async ( ) => {
71+ const key = queryKey ( )
72+ const states : UseInfiniteQueryResult < number > [ ] = [ ]
73+
74+ function Page ( ) {
75+ const state = useInfiniteQuery (
76+ key ,
77+ ( { pageParam = 0 } ) => Number ( pageParam ) ,
78+ {
79+ suspense : true ,
80+ getNextPageParam : lastPage => lastPage + 1 ,
81+ }
82+ )
83+ states . push ( state )
84+ return null
85+ }
86+
87+ renderWithClient (
88+ queryClient ,
89+ < React . Suspense fallback = "loading" >
90+ < Page />
91+ </ React . Suspense >
92+ )
93+
94+ await sleep ( 10 )
95+
96+ expect ( states . length ) . toBe ( 1 )
97+ expect ( states [ 0 ] ) . toMatchObject ( {
98+ data : { pages : [ 0 ] , pageParams : [ undefined ] } ,
99+ status : 'success' ,
100+ } )
101+ } )
102+
68103 it ( 'should not call the queryFn twice when used in Suspense mode' , async ( ) => {
69104 const key = queryKey ( )
70105
You can’t perform that action at this time.
0 commit comments