Skip to content

Commit

Permalink
Add happy test for shadow dom
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Brain authored and Daniel Brain committed Mar 4, 2020
1 parent b1d2465 commit 2e43905
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export { PopupOpenError } from 'belter/src';
export type { ZoidComponent, ZoidComponentInstance } from './component';
export type { RenderOptionsType } from './parent';

export { create, destroy, destroyComponents, destroyAll, Component } from './component';
export { create, destroy, destroyComponents, destroyAll } from './component';
export { PROP_TYPE, PROP_SERIALIZATION, CONTEXT, EVENT } from './constants';
1 change: 0 additions & 1 deletion test/tests/dimensions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('zoid dimensions cases', () => {
}).render(document.body).then(() => {
return componentWindowPromise;
}).then(componentWindow => {

if (componentWindow.innerWidth !== expectedWidth) {
throw new Error(`Expected width to be ${ expectedWidth }, got ${ componentWindow.innerWidth }`);
}
Expand Down
49 changes: 49 additions & 0 deletions test/tests/happy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,53 @@ describe('zoid happy cases', () => {
});
});
});

it('should render a component into the shadow dom', () => {
return wrapPromise(({ expect }) => {

window.__component__ = () => {
return window.zoid.create({
tag: 'test-render-shadow-dom',
url: 'mock://www.child.com/base/test/windows/child/index.htm',
domain: 'mock://www.child.com'
});
};

onWindowOpen().then(expect('onWindowOpen', win => {
if (getParent(win) !== window) {
throw new Error(`Expected window parent to be current window`);
}
}));

const body = document.body;

if (!body) {
throw new Error(`Expected body to be present`);
}

const testElement = document.createElement('div');
body.appendChild(testElement);

if (!testElement.attachShadow) {
throw new Error(`Expected testElement to have attachShadow`);
}

testElement.attachShadow({ mode: 'open' });
const container = document.createElement('div');

if (!testElement.shadowRoot) {
throw new Error(`Expected testElement to have shadowRoot`);
}

testElement.shadowRoot.appendChild(container);

const component = window.__component__();
return component({
onRendered: expect('onRendered', () => {
body.removeChild(testElement);
})
}).render(container);
});
});

});

0 comments on commit 2e43905

Please sign in to comment.