Skip to content

Commit 30dcb50

Browse files
committed
test(core): test bootstrapping an application within a shadow root
This tests that Angular can bootstrap under a shadow root and correctly apply styles to that shadow root rather than the document `<head>` tag.
1 parent 8ddda77 commit 30dcb50

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

packages/platform-browser/test/dom/shadow_dom_spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {Component, NgModule, ViewEncapsulation} from '@angular/core';
1010
import {TestBed} from '@angular/core/testing';
11-
import {BrowserModule} from '../../index';
11+
import {BrowserModule, createApplication} from '../../index';
1212
import {expect} from '@angular/private/testing/matchers';
1313
import {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

Comments
 (0)