Skip to content

Commit

Permalink
Add tests for shadow DOM modes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenle committed Sep 10, 2022
1 parent 8e52b77 commit e6c155a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 34 additions & 0 deletions src/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,38 @@ describe('web components', () => {
});
assert.equal(getShadowHTML(), '<p>Active theme: sunny</p>');
});

it('renders element in shadow dom open mode', async () => {
function ShadowDomOpen() {
return <div className="shadow-child">Shadow DOM Open</div>;
}

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 <div className="shadow-child">Shadow DOM Closed</div>;
}

registerElement(ShadowDomClosed, 'x-shadowdom-closed', [], {
shadow: true,
mode: 'closed',
});

const el = document.createElement('x-shadowdom-closed');
root.appendChild(el);
assert.isTrue(el.shadowRoot === null);
});
});

0 comments on commit e6c155a

Please sign in to comment.