From a614aa810871ea6c2b9f396bb437d2798dd3e131 Mon Sep 17 00:00:00 2001 From: lharries Date: Thu, 25 Jan 2018 17:08:46 +0000 Subject: [PATCH] test(paginator): fix off-by-one error 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 --- src/lib/paginator/paginator.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/paginator/paginator.spec.ts b/src/lib/paginator/paginator.spec.ts index dfc96f977c6c..cccd55300c26 100644 --- a/src/lib/paginator/paginator.spec.ts +++ b/src/lib/paginator/paginator.spec.ts @@ -125,17 +125,17 @@ describe('MatPaginator', () => { expect(component.latestPageEvent ? component.latestPageEvent.pageIndex : null).toBe(0); }); - it('should disable navigating to the next page if at first page', () => { + it('should disable navigating to the next page if at last page', () => { component.goToLastPage(); fixture.detectChanges(); - expect(paginator.pageIndex).toBe(10); + expect(paginator.pageIndex).toBe(9); expect(paginator.hasNextPage()).toBe(false); component.latestPageEvent = null; dispatchMouseEvent(getNextButton(fixture), 'click'); expect(component.latestPageEvent).toBe(null); - expect(paginator.pageIndex).toBe(10); + expect(paginator.pageIndex).toBe(9); }); it('should disable navigating to the previous page if at first page', () => { @@ -310,7 +310,7 @@ class MatPaginatorApp { @ViewChild(MatPaginator) paginator: MatPaginator; goToLastPage() { - this.pageIndex = Math.ceil(this.length / this.pageSize); + this.pageIndex = Math.ceil(this.length / this.pageSize) - 1; } }