Skip to content

Commit bf4ba23

Browse files
authored
test(cdk/scrolling): add test for contracting range (#19030)
Adds a test to the scrolling module for the case where the amount of data is reduced.
1 parent 620e0cb commit bf4ba23

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/cdk/scrolling/virtual-scroll-viewport.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ describe('CdkVirtualScrollViewport', () => {
104104
.toEqual({start: 0, end: 4});
105105
}));
106106

107+
it('should contract the rendered range when changing to less data', fakeAsync(() => {
108+
finishInit(fixture);
109+
110+
expect(viewport.getRenderedRange()).toEqual({start: 0, end: 4});
111+
112+
fixture.componentInstance.items = [0, 1];
113+
fixture.detectChanges();
114+
115+
expect(viewport.getRenderedRange()).toEqual({start: 0, end: 2});
116+
117+
fixture.componentInstance.items = [];
118+
fixture.detectChanges();
119+
120+
expect(viewport.getRenderedRange()).toEqual({start: 0, end: 0});
121+
}));
122+
107123
it('should get the rendered content offset', fakeAsync(() => {
108124
finishInit(fixture);
109125
triggerScroll(viewport, testComponent.itemSize + 5);

0 commit comments

Comments
 (0)