@@ -12,7 +12,6 @@ import {
1212 NgZone ,
1313 TrackByFunction ,
1414 ViewChild ,
15- ViewContainerRef ,
1615 ViewEncapsulation
1716} from '@angular/core' ;
1817import { ComponentFixture , fakeAsync , flush , inject , TestBed } from '@angular/core/testing' ;
@@ -486,49 +485,51 @@ describe('CdkVirtualScrollViewport', () => {
486485
487486 it ( 'should trackBy value by default' , fakeAsync ( ( ) => {
488487 testComponent . items = [ ] ;
489- spyOn ( testComponent . virtualForViewContainer , 'detach ' ) . and . callThrough ( ) ;
488+ spyOn ( testComponent . virtualForOf , '_detachView ' ) . and . callThrough ( ) ;
490489 finishInit ( fixture ) ;
491490
492491 testComponent . items = [ 0 ] ;
493492 fixture . detectChanges ( ) ;
494493 flush ( ) ;
495494
496- expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
495+ expect ( testComponent . virtualForOf . _detachView ) . not . toHaveBeenCalled ( ) ;
497496
498497 testComponent . items = [ 1 ] ;
499498 fixture . detectChanges ( ) ;
500499 flush ( ) ;
501500
502- expect ( testComponent . virtualForViewContainer . detach ) . toHaveBeenCalled ( ) ;
501+ expect ( testComponent . virtualForOf . _detachView ) . toHaveBeenCalled ( ) ;
503502 } ) ) ;
504503
505504 it ( 'should trackBy index when specified' , fakeAsync ( ( ) => {
506505 testComponent . trackBy = i => i ;
507506 testComponent . items = [ ] ;
508- spyOn ( testComponent . virtualForViewContainer , 'detach ' ) . and . callThrough ( ) ;
507+ spyOn ( testComponent . virtualForOf , '_detachView ' ) . and . callThrough ( ) ;
509508 finishInit ( fixture ) ;
510509
511510 testComponent . items = [ 0 ] ;
512511 fixture . detectChanges ( ) ;
513512 flush ( ) ;
514513
515- expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
514+ expect ( testComponent . virtualForOf . _detachView ) . not . toHaveBeenCalled ( ) ;
516515
517516 testComponent . items = [ 1 ] ;
518517 fixture . detectChanges ( ) ;
519518 flush ( ) ;
520519
521- expect ( testComponent . virtualForViewContainer . detach ) . not . toHaveBeenCalled ( ) ;
520+ expect ( testComponent . virtualForOf . _detachView ) . not . toHaveBeenCalled ( ) ;
522521 } ) ) ;
523522
524523 it ( 'should recycle views when template cache is large enough to accommodate' , fakeAsync ( ( ) => {
525524 testComponent . trackBy = i => i ;
526- const spy =
527- spyOn ( testComponent . virtualForViewContainer , 'createEmbeddedView' ) . and . callThrough ( ) ;
525+ const spy = spyOn ( testComponent . virtualForOf , '_createEmbeddedViewAt' )
526+ . and . callThrough ( ) ;
527+
528528 finishInit ( fixture ) ;
529529
530530 // Should create views for the initial rendered items.
531- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 4 ) ;
531+ expect ( testComponent . virtualForOf . _createEmbeddedViewAt )
532+ . toHaveBeenCalledTimes ( 4 ) ;
532533
533534 spy . calls . reset ( ) ;
534535 triggerScroll ( viewport , 10 ) ;
@@ -538,7 +539,8 @@ describe('CdkVirtualScrollViewport', () => {
538539 // As we first start to scroll we need to create one more item. This is because the first item
539540 // is still partially on screen and therefore can't be removed yet. At the same time a new
540541 // item is now partially on the screen at the bottom and so a new view is needed.
541- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 1 ) ;
542+ expect ( testComponent . virtualForOf . _createEmbeddedViewAt )
543+ . toHaveBeenCalledTimes ( 1 ) ;
542544
543545 spy . calls . reset ( ) ;
544546 const maxOffset =
@@ -551,18 +553,21 @@ describe('CdkVirtualScrollViewport', () => {
551553
552554 // As we scroll through the rest of the items, no new views should be created, our existing 5
553555 // can just be recycled as appropriate.
554- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . not . toHaveBeenCalled ( ) ;
556+ expect ( testComponent . virtualForOf . _createEmbeddedViewAt )
557+ . not . toHaveBeenCalled ( ) ;
555558 } ) ) ;
556559
557560 it ( 'should not recycle views when template cache is full' , fakeAsync ( ( ) => {
558561 testComponent . trackBy = i => i ;
559562 testComponent . templateCacheSize = 0 ;
560- const spy =
561- spyOn ( testComponent . virtualForViewContainer , 'createEmbeddedView' ) . and . callThrough ( ) ;
562- finishInit ( fixture ) ;
563+ const spy = spyOn ( testComponent . virtualForOf , '_createEmbeddedViewAt' )
564+ . and . callThrough ( ) ;
565+
566+ finishInit ( fixture ) ;
563567
564568 // Should create views for the initial rendered items.
565- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 4 ) ;
569+ expect ( testComponent . virtualForOf . _createEmbeddedViewAt )
570+ . toHaveBeenCalledTimes ( 4 ) ;
566571
567572 spy . calls . reset ( ) ;
568573 triggerScroll ( viewport , 10 ) ;
@@ -572,7 +577,8 @@ describe('CdkVirtualScrollViewport', () => {
572577 // As we first start to scroll we need to create one more item. This is because the first item
573578 // is still partially on screen and therefore can't be removed yet. At the same time a new
574579 // item is now partially on the screen at the bottom and so a new view is needed.
575- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 1 ) ;
580+ expect ( testComponent . virtualForOf . _createEmbeddedViewAt )
581+ . toHaveBeenCalledTimes ( 1 ) ;
576582
577583 spy . calls . reset ( ) ;
578584 const maxOffset =
@@ -585,7 +591,8 @@ describe('CdkVirtualScrollViewport', () => {
585591
586592 // Since our template cache size is 0, as we scroll through the rest of the items, we need to
587593 // create a new view for each one.
588- expect ( testComponent . virtualForViewContainer . createEmbeddedView ) . toHaveBeenCalledTimes ( 5 ) ;
594+ expect ( testComponent . virtualForOf . _createEmbeddedViewAt )
595+ . toHaveBeenCalledTimes ( 5 ) ;
589596 } ) ) ;
590597
591598 it ( 'should render up to maxBufferPx when buffer dips below minBufferPx' , fakeAsync ( ( ) => {
@@ -828,8 +835,8 @@ function triggerScroll(viewport: CdkVirtualScrollViewport, offset?: number) {
828835} )
829836class FixedSizeVirtualScroll {
830837 @ViewChild ( CdkVirtualScrollViewport , { static : true } ) viewport : CdkVirtualScrollViewport ;
831- @ ViewChild ( CdkVirtualForOf , { static : true } ) virtualForOf : CdkVirtualForOf < any > ;
832- @ViewChild ( CdkVirtualForOf , { read : ViewContainerRef } ) virtualForViewContainer : ViewContainerRef ;
838+ // Casting virtualForOf as any so we can spy on private methods
839+ @ViewChild ( CdkVirtualForOf , { static : true } ) virtualForOf : any ;
833840
834841 @Input ( ) orientation = 'vertical' ;
835842 @Input ( ) viewportSize = 200 ;
@@ -880,7 +887,6 @@ class FixedSizeVirtualScroll {
880887} )
881888class FixedSizeVirtualScrollWithRtlDirection {
882889 @ViewChild ( CdkVirtualScrollViewport , { static : true } ) viewport : CdkVirtualScrollViewport ;
883- @ViewChild ( CdkVirtualForOf , { read : ViewContainerRef } ) virtualForViewContainer : ViewContainerRef ;
884890
885891 @Input ( ) orientation = 'vertical' ;
886892 @Input ( ) viewportSize = 200 ;
0 commit comments