From 2e439052147980b0889fbae23ad0abcbaf0b080b Mon Sep 17 00:00:00 2001 From: Daniel Brain Date: Wed, 4 Mar 2020 10:39:34 -0800 Subject: [PATCH] Add happy test for shadow dom --- src/index.js | 2 +- test/tests/dimensions.jsx | 1 - test/tests/happy.jsx | 49 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 0575f6e5..533bb39f 100644 --- a/src/index.js +++ b/src/index.js @@ -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'; diff --git a/test/tests/dimensions.jsx b/test/tests/dimensions.jsx index d772c1ed..c7ba0698 100644 --- a/test/tests/dimensions.jsx +++ b/test/tests/dimensions.jsx @@ -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 }`); } diff --git a/test/tests/happy.jsx b/test/tests/happy.jsx index e529a37a..50dd8946 100644 --- a/test/tests/happy.jsx +++ b/test/tests/happy.jsx @@ -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); + }); + }); + });