@@ -101,6 +101,7 @@ describe('Portals', () => {
101
101
. not . toBe ( initialParent , 'Expected portal to be out of the initial parent on attach.' ) ;
102
102
expect ( hostContainer . contains ( innerContent ) )
103
103
. toBe ( true , 'Expected content to be inside the outlet on attach.' ) ;
104
+ expect ( testAppComponent . portalOutlet . hasAttached ( ) ) . toBe ( true ) ;
104
105
105
106
testAppComponent . selectedPortal = undefined ;
106
107
fixture . detectChanges ( ) ;
@@ -109,6 +110,7 @@ describe('Portals', () => {
109
110
. toBe ( initialParent , 'Expected portal to be back inside initial parent on detach.' ) ;
110
111
expect ( hostContainer . contains ( innerContent ) )
111
112
. toBe ( false , 'Expected content to be removed from outlet on detach.' ) ;
113
+ expect ( testAppComponent . portalOutlet . hasAttached ( ) ) . toBe ( false ) ;
112
114
} ) ;
113
115
114
116
it ( 'should throw when trying to load an element without a parent into a DOM portal' , ( ) => {
@@ -624,6 +626,30 @@ describe('Portals', () => {
624
626
expect ( ( ) => host . detach ( ) ) . not . toThrow ( ) ;
625
627
} ) ;
626
628
629
+ it ( 'should set hasAttached when the various portal types are attached' , ( ) => {
630
+ const fixture = TestBed . createComponent ( PortalTestApp ) ;
631
+ fixture . detectChanges ( ) ;
632
+ const viewContainerRef = fixture . componentInstance . viewContainerRef ;
633
+
634
+ expect ( host . hasAttached ( ) ) . toBe ( false ) ;
635
+
636
+ host . attachComponentPortal ( new ComponentPortal ( PizzaMsg , viewContainerRef ) ) ;
637
+ expect ( host . hasAttached ( ) ) . toBe ( true ) ;
638
+
639
+ host . detach ( ) ;
640
+ expect ( host . hasAttached ( ) ) . toBe ( false ) ;
641
+
642
+ host . attachTemplatePortal (
643
+ new TemplatePortal ( fixture . componentInstance . templateRef , viewContainerRef ) ) ;
644
+ expect ( host . hasAttached ( ) ) . toBe ( true ) ;
645
+
646
+ host . detach ( ) ;
647
+ expect ( host . hasAttached ( ) ) . toBe ( false ) ;
648
+
649
+ host . attachDomPortal ( new DomPortal ( fixture . componentInstance . domPortalContent ) ) ;
650
+ expect ( host . hasAttached ( ) ) . toBe ( true ) ;
651
+ } ) ;
652
+
627
653
} ) ;
628
654
} ) ;
629
655
@@ -730,7 +756,7 @@ class PortalTestApp {
730
756
fruits = [ 'Apple' , 'Pineapple' , 'Durian' ] ;
731
757
attachedSpy = jasmine . createSpy ( 'attached spy' ) ;
732
758
733
- constructor ( public injector : Injector ) { }
759
+ constructor ( public viewContainerRef : ViewContainerRef , public injector : Injector ) { }
734
760
735
761
get cakePortal ( ) {
736
762
return this . portals . first ;
0 commit comments