@@ -66,7 +66,7 @@ describe('Portals', () => {
6666 ) ;
6767 } ) ;
6868
69- it ( 'should load a template into the portal' , ( ) => {
69+ it ( 'should load a template into the portal outlet ' , ( ) => {
7070 let testAppComponent = fixture . componentInstance ;
7171 let hostContainer = fixture . nativeElement . querySelector ( '.portal-container' ) ;
7272 let templatePortal = new TemplatePortal ( testAppComponent . templateRef , null ! ) ;
@@ -76,6 +76,36 @@ describe('Portals', () => {
7676
7777 // Expect that the content of the attached portal is present and no context is projected
7878 expect ( hostContainer . textContent ) . toContain ( 'Banana' ) ;
79+ expect ( hostContainer . textContent ) . toContain ( 'Pizza' ) ;
80+ expect ( hostContainer . textContent ) . not . toContain ( 'Chocolate' ) ;
81+ expect ( testAppComponent . portalOutlet . portal ) . toBe ( templatePortal ) ;
82+
83+ // We can't test whether it's an instance of an `EmbeddedViewRef` so
84+ // we verify that it's defined and that it's not a ComponentRef.
85+ expect ( testAppComponent . portalOutlet . attachedRef instanceof ComponentRef ) . toBe ( false ) ;
86+ expect ( testAppComponent . portalOutlet . attachedRef ) . toBeTruthy ( ) ;
87+ expect ( testAppComponent . attachedSpy ) . toHaveBeenCalledWith (
88+ testAppComponent . portalOutlet . attachedRef ,
89+ ) ;
90+ } ) ;
91+
92+ it ( 'should load a template with a custom injector into the portal outlet' , ( ) => {
93+ const testAppComponent = fixture . componentInstance ;
94+ const hostContainer = fixture . nativeElement . querySelector ( '.portal-container' ) ;
95+ const templatePortal = new TemplatePortal (
96+ testAppComponent . templateRef ,
97+ null ! ,
98+ undefined ,
99+ new ChocolateInjector ( fixture . componentInstance . injector ) ,
100+ ) ;
101+
102+ testAppComponent . selectedPortal = templatePortal ;
103+ fixture . detectChanges ( ) ;
104+
105+ // Expect that the content of the attached portal is present and no context is projected
106+ expect ( hostContainer . textContent ) . toContain ( 'Banana' ) ;
107+ expect ( hostContainer . textContent ) . toContain ( 'Pizza' ) ;
108+ expect ( hostContainer . textContent ) . toContain ( 'Chocolate' ) ;
79109 expect ( testAppComponent . portalOutlet . portal ) . toBe ( templatePortal ) ;
80110
81111 // We can't test whether it's an instance of an `EmbeddedViewRef` so
@@ -264,6 +294,8 @@ describe('Portals', () => {
264294 // Expect that the content of the attached portal is present.
265295 let hostContainer = fixture . nativeElement . querySelector ( '.portal-container' ) ;
266296 expect ( hostContainer . textContent ) . toContain ( 'Banana' ) ;
297+ expect ( hostContainer . textContent ) . toContain ( 'Pizza' ) ;
298+ expect ( hostContainer . textContent ) . not . toContain ( 'Chocolate' ) ;
267299
268300 // When updating the binding value.
269301 testAppComponent . fruit = 'Mango' ;
@@ -750,15 +782,15 @@ class ArbitraryViewContainerRefComponent {
750782 <ng-template cdk-portal>Cake</ng-template>
751783
752784 <div *cdk-portal>Pie</div>
753- <ng-template cdk-portal let-data> {{fruit}} - {{ data?.status }} </ng-template>
785+ <ng-template cdk-portal let-data> {{fruit}} - {{ data?.status }}! <pizza-msg></pizza-msg> </ng-template>
754786
755787 <ng-template cdk-portal>
756788 <ul>
757789 <li *ngFor="let fruitName of fruits"> {{fruitName}} </li>
758790 </ul>
759791 </ng-template>
760792
761- <ng-template #templateRef let-data> {{fruit}} - {{ data?.status }}!</ng-template>
793+ <ng-template #templateRef let-data> {{fruit}} - {{ data?.status }}! <pizza-msg></pizza-msg> </ng-template>
762794
763795 <div class="dom-portal-parent">
764796 <div #domPortalContent>
0 commit comments