Skip to content

Commit 9d8df14

Browse files
Daniel BrainDaniel Brain
Daniel Brain
authored and
Daniel Brain
committed
Add happy test for shadow dom
1 parent b1d2465 commit 9d8df14

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export { PopupOpenError } from 'belter/src';
55
export type { ZoidComponent, ZoidComponentInstance } from './component';
66
export type { RenderOptionsType } from './parent';
77

8-
export { create, destroy, destroyComponents, destroyAll, Component } from './component';
8+
export { create, destroy, destroyComponents, destroyAll } from './component';
99
export { PROP_TYPE, PROP_SERIALIZATION, CONTEXT, EVENT } from './constants';

test/tests/happy.jsx

+44
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,48 @@ describe('zoid happy cases', () => {
410410
});
411411
});
412412
});
413+
414+
it('should render a component into the shadow dom', () => {
415+
return wrapPromise(({ expect }) => {
416+
417+
window.__component__ = () => {
418+
return window.zoid.create({
419+
tag: 'test-render-shadow-dom',
420+
url: 'mock://www.child.com/base/test/windows/child/index.htm',
421+
domain: 'mock://www.child.com'
422+
});
423+
};
424+
425+
onWindowOpen().then(expect('onWindowOpen', win => {
426+
if (getParent(win) !== window) {
427+
throw new Error(`Expected window parent to be current window`);
428+
}
429+
}));
430+
431+
const body = document.body;
432+
433+
if (!body) {
434+
throw new Error(`Expected body to be present`);
435+
}
436+
437+
if (!body.attachShadow) {
438+
throw new Error(`Expected body to have attachShadow`);
439+
}
440+
441+
body.attachShadow({ mode: 'open' });
442+
const container = document.createElement('div');
443+
444+
if (!body.shadowRoot) {
445+
throw new Error(`Expected body to have shadowRoot`);
446+
}
447+
448+
body.shadowRoot.appendChild(container);
449+
450+
const component = window.__component__();
451+
return component({
452+
onRendered: expect('onRendered')
453+
}).render(container);
454+
});
455+
});
456+
413457
});

0 commit comments

Comments
 (0)