@@ -17,7 +17,8 @@ describe('useSWR - focus', () => {
1717 const key = createKey ( )
1818 function Page ( ) {
1919 const { data } = useSWR ( key , ( ) => value ++ , {
20- dedupingInterval : 0
20+ dedupingInterval : 0 ,
21+ focusThrottleInterval : 0
2122 } )
2223 return < div > data: { data } </ div >
2324 }
@@ -131,19 +132,17 @@ describe('useSWR - focus', () => {
131132 await screen . findByText ( 'data: 0' )
132133
133134 await waitForNextTick ( )
134- // trigger revalidation
135- await focusWindow ( )
136135 // still in throttling interval
137136 await act ( ( ) => sleep ( 20 ) )
138137 // should be throttled
139138 await focusWindow ( )
140- await screen . findByText ( 'data: 1 ' )
139+ await screen . findByText ( 'data: 0 ' )
141140 // wait for focusThrottleInterval
142141 await act ( ( ) => sleep ( 100 ) )
143142
144143 // trigger revalidation again
145144 await focusWindow ( )
146- await screen . findByText ( 'data: 2 ' )
145+ await screen . findByText ( 'data: 1 ' )
147146 } )
148147
149148 it ( 'focusThrottleInterval should be stateful' , async ( ) => {
@@ -168,17 +167,17 @@ describe('useSWR - focus', () => {
168167 await screen . findByText ( 'data: 0' )
169168
170169 await waitForNextTick ( )
171- // trigger revalidation
170+ // trigger revalidation, won't revalidate as within 50ms
172171 await focusWindow ( )
173172 // wait for throttle interval
174173 await act ( ( ) => sleep ( 100 ) )
175- // trigger revalidation
174+ // trigger revalidation, will revalidate as 50ms passed
176175 await focusWindow ( )
177- await screen . findByText ( 'data: 2 ' )
176+ await screen . findByText ( 'data: 1 ' )
178177
179178 await waitForNextTick ( )
180179 // increase focusThrottleInterval
181- fireEvent . click ( screen . getByText ( 'data: 2 ' ) )
180+ fireEvent . click ( screen . getByText ( 'data: 1 ' ) )
182181 // wait for throttle interval
183182 await act ( ( ) => sleep ( 100 ) )
184183 // trigger revalidation
@@ -187,15 +186,15 @@ describe('useSWR - focus', () => {
187186 await act ( ( ) => sleep ( 100 ) )
188187 // should be throttled
189188 await focusWindow ( )
190- await screen . findByText ( 'data: 3 ' )
189+ await screen . findByText ( 'data: 2 ' )
191190
192191 // wait for throttle interval
193192 await act ( ( ) => sleep ( 150 ) )
194193 // trigger revalidation
195194 await focusWindow ( )
196195 // wait for throttle intervals
197196 await act ( ( ) => sleep ( 150 ) )
198- await screen . findByText ( 'data: 4 ' )
197+ await screen . findByText ( 'data: 3 ' )
199198 } )
200199
201200 it ( 'should revalidate on focus even with custom cache' , async ( ) => {
@@ -205,7 +204,8 @@ describe('useSWR - focus', () => {
205204 function Page ( ) {
206205 const { data } = useSWR ( key , ( ) => value ++ , {
207206 revalidateOnFocus : true ,
208- dedupingInterval : 0
207+ dedupingInterval : 0 ,
208+ focusThrottleInterval : 0
209209 } )
210210 return < div > data: { data } </ div >
211211 }
0 commit comments