From 9d8df14ed922d20eace673c4971f07314928462e 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/happy.jsx | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) 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/happy.jsx b/test/tests/happy.jsx index e529a37a..2a806273 100644 --- a/test/tests/happy.jsx +++ b/test/tests/happy.jsx @@ -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); + }); + }); + });