Skip to content

Commit fac08f3

Browse files
lharriesjelbourn
authored andcommitted
test(paginator): fix off-by-one error (#9604)
Whilst there are 10 pages they are starting from index 0 and therefore the last page is in fact index 9. This error was repeated both in the length calculation and in the assertion statements, therefore the test passed when it should have failed. Discovered in #9278
1 parent 2f579b3 commit fac08f3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib/paginator/paginator.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,17 @@ describe('MatPaginator', () => {
125125
expect(component.latestPageEvent ? component.latestPageEvent.pageIndex : null).toBe(0);
126126
});
127127

128-
it('should disable navigating to the next page if at first page', () => {
128+
it('should disable navigating to the next page if at last page', () => {
129129
component.goToLastPage();
130130
fixture.detectChanges();
131-
expect(paginator.pageIndex).toBe(10);
131+
expect(paginator.pageIndex).toBe(9);
132132
expect(paginator.hasNextPage()).toBe(false);
133133

134134
component.latestPageEvent = null;
135135
dispatchMouseEvent(getNextButton(fixture), 'click');
136136

137137
expect(component.latestPageEvent).toBe(null);
138-
expect(paginator.pageIndex).toBe(10);
138+
expect(paginator.pageIndex).toBe(9);
139139
});
140140

141141
it('should disable navigating to the previous page if at first page', () => {
@@ -310,7 +310,7 @@ class MatPaginatorApp {
310310
@ViewChild(MatPaginator) paginator: MatPaginator;
311311

312312
goToLastPage() {
313-
this.pageIndex = Math.ceil(this.length / this.pageSize);
313+
this.pageIndex = Math.ceil(this.length / this.pageSize) - 1;
314314
}
315315
}
316316

0 commit comments

Comments
 (0)