88
99import { Component , NgModule , ViewEncapsulation } from '@angular/core' ;
1010import { TestBed } from '@angular/core/testing' ;
11- import { BrowserModule } from '../../index' ;
11+ import { BrowserModule , createApplication } from '../../index' ;
1212import { expect } from '@angular/private/testing/matchers' ;
1313import { isNode } from '@angular/private/testing' ;
1414
@@ -23,6 +23,10 @@ describe('ShadowDOM Support', () => {
2323 TestBed . configureTestingModule ( { imports : [ TestModule ] } ) ;
2424 } ) ;
2525
26+ afterEach ( ( ) => {
27+ for ( const child of document . body . children ) child . remove ( ) ;
28+ } ) ;
29+
2630 it ( 'should attach and use a shadowRoot when ViewEncapsulation.ShadowDom is set' , ( ) => {
2731 const compEl = TestBed . createComponent ( ShadowComponent ) . nativeElement ;
2832 expect ( compEl . shadowRoot ! . textContent ) . toEqual ( 'Hello World' ) ;
@@ -81,6 +85,28 @@ describe('ShadowDOM Support', () => {
8185 expect ( articleContent . assignedSlot ) . toBe ( articleSlot ) ;
8286 expect ( articleSubcontent . assignedSlot ) . toBe ( articleSlot ) ;
8387 } ) ;
88+
89+ it ( 'should support bootstrapping an application underneath a shadow root' , async ( ) => {
90+ @Component ( {
91+ selector : 'app-root' ,
92+ template : `Hello world!` ,
93+ styles : `:host {color: red;}` ,
94+ } )
95+ class AppRoot { }
96+
97+ const container = document . createElement ( 'div' ) ;
98+ const shadowRoot = container . attachShadow ( { mode : 'open' } ) ;
99+ const appRoot = document . createElement ( 'my-app' ) ;
100+ shadowRoot . appendChild ( appRoot ) ;
101+ document . body . appendChild ( container ) ;
102+
103+ const appRef = await createApplication ( ) ;
104+ const componentRef = appRef . bootstrap ( AppRoot , appRoot ) ;
105+
106+ expect ( getComputedStyle ( componentRef . location . nativeElement ) . color ) . toBe ( 'rgb(255, 0, 0)' ) ;
107+
108+ expect ( document . head . innerHTML ) . not . toContain ( '<style>' ) ;
109+ } ) ;
84110} ) ;
85111
86112@Component ( {
0 commit comments