Skip to content

Commit 4cd29ab

Browse files
committed
βœ… pageIndex test; πŸ›  return if bad element
1 parent 8a27ef9 commit 4cd29ab

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

β€Žjs/core.jsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function InfiniteScroll( element, options ) {
3737

3838
if ( !queryElem ) {
3939
console.error( 'Bad element for InfiniteScroll: ' + ( queryElem || element ) );
40+
return;
4041
}
4142
element = queryElem;
4243
// do not initialize twice on same element

β€Žtest/index.htmlβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<script src="unit/path.js"></script>
3232
<script src="unit/page-load.js"></script>
3333
<script src="unit/page-load-error.js"></script>
34+
<script src="unit/page-index.js"></script>
3435
<script src="unit/check-last-page.js"></script>
3536
<script src="unit/prefill-window.js"></script>
3637
<script src="unit/prefill-element.js"></script>
@@ -66,6 +67,12 @@ <h2>page load error</h2>
6667
<div class="post">page 1, post 1</div>
6768
</div>
6869

70+
<h2>pageIndex</h2>
71+
<div class="demo demo--page-index">
72+
<div class="post">page 4, post 1</div>
73+
</div>
74+
<p><a class="page-index-next-link" href="page/5.html">Page 5</a></p>
75+
6976
<h2>check last page</h2>
7077
<div class="demo demo--check-last-page">
7178
<div class="post">page 1, post 1</div>

β€Žtest/unit/page-index.jsβ€Ž

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
QUnit.test( 'pageIndex', function( assert ) {
2+
3+
var demoElem = document.querySelector('.demo--page-index');
4+
5+
var infScroll = new InfiniteScroll( demoElem, {
6+
path: '.page-index-next-link',
7+
history: false,
8+
scrollThreshold: false,
9+
});
10+
11+
assert.equal( infScroll.pageIndex, 4, 'pageIndex from path element' );
12+
13+
infScroll.destroy();
14+
15+
// pageIndex from URL with {{#}} path
16+
var prevURL = location.href;
17+
// set URL with page number
18+
history.replaceState( null, document.title, 'page/7' );
19+
infScroll = new InfiniteScroll( demoElem, {
20+
path: 'page/{{#}}',
21+
history: false,
22+
scrollThreshold: false,
23+
});
24+
25+
assert.equal( infScroll.pageIndex, 7, 'pageIndex from URL with {{#}}' );
26+
27+
history.replaceState( null, document.title, prevURL );
28+
29+
});

0 commit comments

Comments
Β (0)