@@ -36,17 +36,9 @@ function getPageAssertions() {
3636 serialT . fail ( 'last event should not trigger when not last page' ) ;
3737 }
3838
39- await ( function ( ) {
40- let promise = new Promise ( function ( resolve ) {
41- infScroll . once ( 'append' , function ( ) {
42- infScroll . off ( 'last' , onLast ) ;
43- resolve ( ) ;
44- } ) ;
45- } ) ;
46- // load page 2
47- infScroll . loadNextPage ( ) ;
48- return promise ;
49- } ) ( ) ;
39+ await infScroll . loadNextPage ( ) . then ( function ( ) {
40+ infScroll . off ( 'last' , onLast ) ;
41+ } ) ;
5042
5143 let promise = new Promise ( function ( resolve ) {
5244 infScroll . once ( 'last' , function ( ) {
@@ -88,13 +80,15 @@ test( 'checkLastPage: ".selector-string"', withPage, async function( t, page ) {
8880 assertions . forEach ( ( { method, args } ) => t [ method ] ( ...args ) ) ;
8981} ) ;
9082
91- test ( 'checkLastPage with path: function() {} ' , withPage , async function ( t , page ) {
83+ test ( 'checkLastPage with empty page ' , withPage , async function ( t , page ) {
9284 await page . evaluate ( function ( ) {
9385 window . infScroll = new InfiniteScroll ( '.container' , {
9486 // provide only page/2.html, then falsy
9587 path : function ( ) {
96- if ( this . pageIndex < 3 ) {
88+ if ( this . pageIndex < 2 ) {
9789 return `page/${ this . pageIndex + 1 } .html` ;
90+ } else {
91+ return 'page/empty.html' ;
9892 }
9993 } ,
10094 // checkLastPage: true, // true by default
@@ -105,3 +99,32 @@ test( 'checkLastPage with path: function() {}', withPage, async function( t, pag
10599 let assertions = await page . evaluate ( getPageAssertions ( ) ) ;
106100 assertions . forEach ( ( { method, args } ) => t [ method ] ( ...args ) ) ;
107101} ) ;
102+
103+ test ( 'checkLastPage with path: function() {}' , withPage , async function ( t , page ) {
104+ let assertions = await page . evaluate ( function ( ) {
105+ let infScroll = new InfiniteScroll ( '.container' , {
106+ // provide only page/2.html, then falsy
107+ path : function ( ) {
108+ if ( this . pageIndex < 2 ) {
109+ return `page/${ this . pageIndex + 1 } .html` ;
110+ }
111+ } ,
112+ // checkLastPage: true, // true by default
113+ append : '.post' ,
114+ } ) ;
115+
116+ // function returning falsey will trigger last right after pageLoad
117+ let promise = new Promise ( function ( resolve ) {
118+ infScroll . once ( 'last' , function ( ) {
119+ serialT . is ( infScroll . pageIndex , 2 ) ;
120+ resolve ( serialT . assertions ) ;
121+ } ) ;
122+ } ) ;
123+
124+ // load page 2
125+ infScroll . loadNextPage ( ) ;
126+ return promise ;
127+ } ) ;
128+
129+ assertions . forEach ( ( { method, args } ) => t [ method ] ( ...args ) ) ;
130+ } ) ;
0 commit comments