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 b2ac4f9
Showing 1 changed file with 34 additions and 0 deletions.
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 b2ac4f9

Please sign in to comment.