@@ -58,8 +58,8 @@ describe('usePagination', () => {
5858 myTotalPage : { a : { b : { totalPage : 99 } } } ,
5959 } ) ;
6060
61- fetchMock . get ( normalApi , normalMockData ) ;
62- fetchMock . get ( customPropertyApi , customPropertyMockData ) ;
61+ fetchMock . get ( normalApi , normalMockData , { delay : 1000 } ) ;
62+ fetchMock . get ( customPropertyApi , customPropertyMockData , { delay : 1000 } ) ;
6363
6464 const originalError = console . error ;
6565 beforeEach ( ( ) => {
@@ -230,21 +230,17 @@ describe('usePagination', () => {
230230 const wrapper = shallowMount (
231231 defineComponent ( {
232232 setup ( ) {
233- const {
234- data,
235- total,
236- params,
237- current,
238- pageSize,
239- totalPage,
240- } = usePagination ( customPropertyApi , {
241- pagination : {
242- currentKey : 'myCurrent' ,
243- pageSizeKey : 'myPageSize' ,
244- totalKey : 'myTotal.a.b.total' ,
245- totalPageKey : 'myTotalPage.a.b.totalPage' ,
233+ const { total, params, current, pageSize, totalPage } = usePagination (
234+ customPropertyApi ,
235+ {
236+ pagination : {
237+ currentKey : 'myCurrent' ,
238+ pageSizeKey : 'myPageSize' ,
239+ totalKey : 'myTotal.a.b.total' ,
240+ totalPageKey : 'myTotalPage.a.b.totalPage' ,
241+ } ,
246242 } ,
247- } ) ;
243+ ) ;
248244 return ( ) => (
249245 < div >
250246 < div class = "params" > { JSON . stringify ( params . value ) } </ div >
@@ -287,4 +283,65 @@ describe('usePagination', () => {
287283 }
288284 expect ( fn ) . toHaveBeenCalledTimes ( 1 ) ;
289285 } ) ;
286+
287+ test ( '`current` and `pageSize` `current` and `pageSize` can modify and can trigger request' , async ( ) => {
288+ let _current = 1 ;
289+ let _pageSize = 10 ;
290+ const wrapper = shallowMount (
291+ defineComponent ( {
292+ setup ( ) {
293+ const { loading, current, pageSize, params } = usePagination (
294+ normalApi ,
295+ ) ;
296+ return ( ) => (
297+ < div >
298+ < button
299+ class = "currentBtn"
300+ onClick = { ( ) => ( _current = ++ current . value ) }
301+ />
302+ < button
303+ class = "pageSizeBtn"
304+ onClick = { ( ) => ( _pageSize = ++ pageSize . value ) }
305+ />
306+ < div class = "current" > { current . value } </ div >
307+ < div class = "pageSize" > { pageSize . value } </ div >
308+ < div class = "loading" > { `${ loading . value } ` } </ div >
309+ < div class = "params" > { JSON . stringify ( params . value ) } </ div >
310+ </ div >
311+ ) ;
312+ } ,
313+ } ) ,
314+ ) ;
315+
316+ const currentBtn = wrapper . find ( '.currentBtn' ) ;
317+ const pageSizeBtn = wrapper . find ( '.pageSizeBtn' ) ;
318+ const currentEl = wrapper . find ( '.current' ) ;
319+ const paramsEl = wrapper . find ( '.params' ) ;
320+ const pageSizeEl = wrapper . find ( '.pageSize' ) ;
321+ const loadingEl = wrapper . find ( '.loading' ) ;
322+
323+ for ( let index = 0 ; index < 100 ; index ++ ) {
324+ await currentBtn . trigger ( 'click' ) ;
325+ expect ( loadingEl . text ( ) ) . toBe ( 'true' ) ;
326+ await waitForTime ( 1000 ) ;
327+ expect ( loadingEl . text ( ) ) . toBe ( 'false' ) ;
328+ expect ( paramsEl . text ( ) ) . toBe (
329+ `[{"current":${ _current } ,"pageSize":${ _pageSize } }]` ,
330+ ) ;
331+ expect ( currentEl . text ( ) ) . toBe ( `${ _current } ` ) ;
332+ expect ( pageSizeEl . text ( ) ) . toBe ( `${ _pageSize } ` ) ;
333+ }
334+
335+ for ( let index = 0 ; index < 100 ; index ++ ) {
336+ await pageSizeBtn . trigger ( 'click' ) ;
337+ expect ( loadingEl . text ( ) ) . toBe ( 'true' ) ;
338+ await waitForTime ( 1000 ) ;
339+ expect ( loadingEl . text ( ) ) . toBe ( 'false' ) ;
340+ expect ( paramsEl . text ( ) ) . toBe (
341+ `[{"current":${ _current } ,"pageSize":${ _pageSize } }]` ,
342+ ) ;
343+ expect ( currentEl . text ( ) ) . toBe ( `${ _current } ` ) ;
344+ expect ( pageSizeEl . text ( ) ) . toBe ( `${ _pageSize } ` ) ;
345+ }
346+ } ) ;
290347} ) ;
0 commit comments