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 9d8df14
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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';
44 changes: 44 additions & 0 deletions test/tests/happy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,48 @@ 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`);
}

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

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

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

body.shadowRoot.appendChild(container);

const component = window.__component__();
return component({
onRendered: expect('onRendered')
}).render(container);
});
});

});

0 comments on commit 9d8df14

Please sign in to comment.