@@ -66,7 +66,7 @@ describe('Portals', () => {
66
66
) ;
67
67
} ) ;
68
68
69
- it ( 'should load a template into the portal' , ( ) => {
69
+ it ( 'should load a template into the portal outlet ' , ( ) => {
70
70
let testAppComponent = fixture . componentInstance ;
71
71
let hostContainer = fixture . nativeElement . querySelector ( '.portal-container' ) ;
72
72
let templatePortal = new TemplatePortal ( testAppComponent . templateRef , null ! ) ;
@@ -76,6 +76,36 @@ describe('Portals', () => {
76
76
77
77
// Expect that the content of the attached portal is present and no context is projected
78
78
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' ) ;
79
109
expect ( testAppComponent . portalOutlet . portal ) . toBe ( templatePortal ) ;
80
110
81
111
// We can't test whether it's an instance of an `EmbeddedViewRef` so
@@ -264,6 +294,8 @@ describe('Portals', () => {
264
294
// Expect that the content of the attached portal is present.
265
295
let hostContainer = fixture . nativeElement . querySelector ( '.portal-container' ) ;
266
296
expect ( hostContainer . textContent ) . toContain ( 'Banana' ) ;
297
+ expect ( hostContainer . textContent ) . toContain ( 'Pizza' ) ;
298
+ expect ( hostContainer . textContent ) . not . toContain ( 'Chocolate' ) ;
267
299
268
300
// When updating the binding value.
269
301
testAppComponent . fruit = 'Mango' ;
@@ -750,15 +782,15 @@ class ArbitraryViewContainerRefComponent {
750
782
<ng-template cdk-portal>Cake</ng-template>
751
783
752
784
<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>
754
786
755
787
<ng-template cdk-portal>
756
788
<ul>
757
789
<li *ngFor="let fruitName of fruits"> {{fruitName}} </li>
758
790
</ul>
759
791
</ng-template>
760
792
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>
762
794
763
795
<div class="dom-portal-parent">
764
796
<div #domPortalContent>
0 commit comments