Skip to content

Commit b90e01b

Browse files
committed
address comments
1 parent 6e79ab1 commit b90e01b

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -360,55 +360,56 @@ describe('CdkVirtualScrollViewport', () => {
360360

361361
it('should trackBy value by default', fakeAsync(() => {
362362
testComponent.items = [];
363-
spyOn(testComponent.cdkForOfViewContainer, 'detach').and.callThrough();
363+
spyOn(testComponent.virtualForViewContainer, 'detach').and.callThrough();
364364
finishInit(fixture);
365365

366366
testComponent.items = [0];
367367
fixture.detectChanges();
368368

369-
expect(testComponent.cdkForOfViewContainer.detach).not.toHaveBeenCalled();
369+
expect(testComponent.virtualForViewContainer.detach).not.toHaveBeenCalled();
370370

371371
testComponent.items = [1];
372372
fixture.detectChanges();
373373

374-
expect(testComponent.cdkForOfViewContainer.detach).toHaveBeenCalled();
374+
expect(testComponent.virtualForViewContainer.detach).toHaveBeenCalled();
375375
}));
376376

377377
it('should trackBy index when specified', fakeAsync(() => {
378378
testComponent.trackBy = i => i;
379379
testComponent.items = [];
380-
spyOn(testComponent.cdkForOfViewContainer, 'detach').and.callThrough();
380+
spyOn(testComponent.virtualForViewContainer, 'detach').and.callThrough();
381381
finishInit(fixture);
382382

383383
testComponent.items = [0];
384384
fixture.detectChanges();
385385

386-
expect(testComponent.cdkForOfViewContainer.detach).not.toHaveBeenCalled();
386+
expect(testComponent.virtualForViewContainer.detach).not.toHaveBeenCalled();
387387

388388
testComponent.items = [1];
389389
fixture.detectChanges();
390390

391-
expect(testComponent.cdkForOfViewContainer.detach).not.toHaveBeenCalled();
391+
expect(testComponent.virtualForViewContainer.detach).not.toHaveBeenCalled();
392392
}));
393393

394394
it('should recycle views when template cache is large enough to accommodate', fakeAsync(() => {
395395
testComponent.trackBy = i => i;
396-
spyOn(testComponent.cdkForOfViewContainer, 'createEmbeddedView').and.callThrough();
396+
const spy =
397+
spyOn(testComponent.virtualForViewContainer, 'createEmbeddedView').and.callThrough();
397398
finishInit(fixture);
398399

399400
// Should create views for the initial rendered items.
400-
expect(testComponent.cdkForOfViewContainer.createEmbeddedView).toHaveBeenCalledTimes(4);
401+
expect(testComponent.virtualForViewContainer.createEmbeddedView).toHaveBeenCalledTimes(4);
401402

402-
(testComponent.cdkForOfViewContainer.createEmbeddedView as any).calls.reset();
403+
spy.calls.reset();
403404
triggerScroll(viewport, 10);
404405
fixture.detectChanges();
405406

406407
// As we first start to scroll we need to create one more item. This is because the first item
407408
// is still partially on screen and therefore can't be removed yet. At the same time a new
408409
// item is now partially on the screen at the bottom and so a new view is needed.
409-
expect(testComponent.cdkForOfViewContainer.createEmbeddedView).toHaveBeenCalledTimes(1);
410+
expect(testComponent.virtualForViewContainer.createEmbeddedView).toHaveBeenCalledTimes(1);
410411

411-
(testComponent.cdkForOfViewContainer.createEmbeddedView as any).calls.reset();
412+
spy.calls.reset();
412413
const maxOffset =
413414
testComponent.itemSize * testComponent.items.length - testComponent.viewportSize;
414415
for (let offset = 10; offset <= maxOffset; offset += 10) {
@@ -418,28 +419,29 @@ describe('CdkVirtualScrollViewport', () => {
418419

419420
// As we scroll through the rest of the items, no new views should be created, our existing 5
420421
// can just be recycled as appropriate.
421-
expect(testComponent.cdkForOfViewContainer.createEmbeddedView).not.toHaveBeenCalled();
422+
expect(testComponent.virtualForViewContainer.createEmbeddedView).not.toHaveBeenCalled();
422423
}));
423424

424425
it('should not recycle views when template cache is full', fakeAsync(() => {
425426
testComponent.trackBy = i => i;
426427
testComponent.templateCacheSize = 0;
427-
spyOn(testComponent.cdkForOfViewContainer, 'createEmbeddedView').and.callThrough();
428+
const spy =
429+
spyOn(testComponent.virtualForViewContainer, 'createEmbeddedView').and.callThrough();
428430
finishInit(fixture);
429431

430432
// Should create views for the initial rendered items.
431-
expect(testComponent.cdkForOfViewContainer.createEmbeddedView).toHaveBeenCalledTimes(4);
433+
expect(testComponent.virtualForViewContainer.createEmbeddedView).toHaveBeenCalledTimes(4);
432434

433-
(testComponent.cdkForOfViewContainer.createEmbeddedView as any).calls.reset();
435+
spy.calls.reset();
434436
triggerScroll(viewport, 10);
435437
fixture.detectChanges();
436438

437439
// As we first start to scroll we need to create one more item. This is because the first item
438440
// is still partially on screen and therefore can't be removed yet. At the same time a new
439441
// item is now partially on the screen at the bottom and so a new view is needed.
440-
expect(testComponent.cdkForOfViewContainer.createEmbeddedView).toHaveBeenCalledTimes(1);
442+
expect(testComponent.virtualForViewContainer.createEmbeddedView).toHaveBeenCalledTimes(1);
441443

442-
(testComponent.cdkForOfViewContainer.createEmbeddedView as any).calls.reset();
444+
spy.calls.reset();
443445
const maxOffset =
444446
testComponent.itemSize * testComponent.items.length - testComponent.viewportSize;
445447
for (let offset = 10; offset <= maxOffset; offset += 10) {
@@ -449,7 +451,7 @@ describe('CdkVirtualScrollViewport', () => {
449451

450452
// Since our template cache size is 0, as we scroll through the rest of the items, we need to
451453
// create a new view for each one.
452-
expect(testComponent.cdkForOfViewContainer.createEmbeddedView).toHaveBeenCalledTimes(5);
454+
expect(testComponent.virtualForViewContainer.createEmbeddedView).toHaveBeenCalledTimes(5);
453455
}));
454456
});
455457
});
@@ -506,7 +508,7 @@ function triggerScroll(viewport: CdkVirtualScrollViewport, offset?: number) {
506508
})
507509
class FixedVirtualScroll {
508510
@ViewChild(CdkVirtualScrollViewport) viewport: CdkVirtualScrollViewport;
509-
@ViewChild(CdkVirtualForOf, {read: ViewContainerRef}) cdkForOfViewContainer: ViewContainerRef;
511+
@ViewChild(CdkVirtualForOf, {read: ViewContainerRef}) virtualForViewContainer: ViewContainerRef;
510512

511513
@Input() orientation = 'vertical';
512514
@Input() viewportSize = 200;

0 commit comments

Comments
 (0)