From e6c155aa35366d20280351f6dfd0cf4f7887caf2 Mon Sep 17 00:00:00 2001 From: Steven Le Date: Sat, 10 Sep 2022 08:30:26 -0700 Subject: [PATCH] Add tests for shadow DOM modes --- package.json | 1 + src/index.test.jsx | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/package.json b/package.json index 688507d..0eb3855 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "@web/dev-server-esbuild": "^0.2.2", "@web/test-runner": "^0.7.12", "@web/test-runner-playwright": "^0.5.4", + "@web/test-runner-puppeteer": "^0.10.5", "eslint": "^7.7.0", "eslint-config-developit": "^1.2.0", "get-stream": "^6.0.0", diff --git a/src/index.test.jsx b/src/index.test.jsx index 00da646..f293941 100644 --- a/src/index.test.jsx +++ b/src/index.test.jsx @@ -245,4 +245,38 @@ describe('web components', () => { }); assert.equal(getShadowHTML(), '

Active theme: sunny

'); }); + + it('renders element in shadow dom open mode', async () => { + function ShadowDomOpen() { + return
Shadow DOM Open
; + } + + registerElement(ShadowDomOpen, 'x-shadowdom-open', [], { + shadow: true, + mode: 'open', + }); + + const el = document.createElement('x-shadowdom-open'); + root.appendChild(el); + const shadowRoot = el.shadowRoot; + assert.isTrue(!!shadowRoot); + const child = shadowRoot.querySelector('.shadow-child'); + assert.isTrue(!!child); + assert.equal(child.textContent, 'Shadow DOM Open'); + }); + + it('renders element in shadow dom closed mode', async () => { + function ShadowDomClosed() { + return
Shadow DOM Closed
; + } + + registerElement(ShadowDomClosed, 'x-shadowdom-closed', [], { + shadow: true, + mode: 'closed', + }); + + const el = document.createElement('x-shadowdom-closed'); + root.appendChild(el); + assert.isTrue(el.shadowRoot === null); + }); });