Skip to content

Commit 2e43905

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

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
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/dimensions.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ describe('zoid dimensions cases', () => {
4242
}).render(document.body).then(() => {
4343
return componentWindowPromise;
4444
}).then(componentWindow => {
45-
4645
if (componentWindow.innerWidth !== expectedWidth) {
4746
throw new Error(`Expected width to be ${ expectedWidth }, got ${ componentWindow.innerWidth }`);
4847
}

test/tests/happy.jsx

+49
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,53 @@ 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+
const testElement = document.createElement('div');
438+
body.appendChild(testElement);
439+
440+
if (!testElement.attachShadow) {
441+
throw new Error(`Expected testElement to have attachShadow`);
442+
}
443+
444+
testElement.attachShadow({ mode: 'open' });
445+
const container = document.createElement('div');
446+
447+
if (!testElement.shadowRoot) {
448+
throw new Error(`Expected testElement to have shadowRoot`);
449+
}
450+
451+
testElement.shadowRoot.appendChild(container);
452+
453+
const component = window.__component__();
454+
return component({
455+
onRendered: expect('onRendered', () => {
456+
body.removeChild(testElement);
457+
})
458+
}).render(container);
459+
});
460+
});
461+
413462
});

0 commit comments

Comments
 (0)