@@ -170,6 +170,43 @@ describe('usePagination', () => {
170170 expect ( items [ 1 ] ) . to . have . property ( 'disabled' , true ) ;
171171 } ) ;
172172
173+ it ( 'does not render a stale uncontrolled page when count decreases' , ( ) => {
174+ const result = React . createRef ( ) ;
175+
176+ function TestCase ( { count } ) {
177+ const hookResult = usePagination ( {
178+ count,
179+ defaultPage : 11 ,
180+ boundaryCount : 0 ,
181+ siblingCount : 0 ,
182+ } ) ;
183+ React . useEffect ( ( ) => {
184+ result . current = hookResult ;
185+ } , [ hookResult ] ) ;
186+ return null ;
187+ }
188+
189+ const { rerender } = render ( < TestCase count = { 11 } /> ) ;
190+ expect ( serialize ( result . current . items ) ) . to . deep . equal ( [ 'previous' , 11 , 'next' ] ) ;
191+
192+ rerender ( < TestCase count = { 5 } /> ) ;
193+ expect ( serialize ( result . current . items ) ) . to . deep . equal ( [
194+ 'previous' ,
195+ 'start-ellipsis' ,
196+ 4 ,
197+ 5 ,
198+ 'next' ,
199+ ] ) ;
200+ } ) ;
201+
202+ it ( 'does not render an out-of-range controlled page' , ( ) => {
203+ const items = renderHook ( ( ) =>
204+ usePagination ( { count : 5 , page : 0 , boundaryCount : 0 , siblingCount : 0 } ) ,
205+ ) . result . current . items ;
206+
207+ expect ( serialize ( items ) ) . to . deep . equal ( [ 'previous' , 1 , 2 , 'end-ellipsis' , 'next' ] ) ;
208+ } ) ;
209+
173210 it ( 'should support boundaryCount={0}' , ( ) => {
174211 const items = renderHook ( ( ) =>
175212 usePagination ( { count : 11 , page : 6 , boundaryCount : 0 , siblingCount : 1 } ) ,
0 commit comments