Skip to content

Commit

Permalink
fix: add tests for deep-contains function
Browse files Browse the repository at this point in the history
  • Loading branch information
okadurin committed Jul 26, 2024
1 parent 9607732 commit 6202f13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-planets-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

improve deep-contains function so it works correctly with slots
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,31 @@ describe('deepContains()', () => {
expect(deepContains(element, elementFirstChildShadowChildShadow)).to.be.true;
expect(deepContains(element, elementFirstChildShadowChildShadowLastChild)).to.be.true;
});

it('returns true if the element, which is located in ShadowsRoot, contains a target element, located in the LightDom', async () => {
const mainElement = /** @type {HTMLElement} */ (await fixture('<div id="main"></div>'));
mainElement.innerHTML = `
<div slot="content" id="light-el-content">Content</div>
`;
const shadowRoot = mainElement.attachShadow({ mode: 'open' });
shadowRoot.innerHTML = `
<div id="dialog-wrapper">
<div id="dialog-header">
Header
</div>
<div id="dialog-content">
<slot name="content" id="shadow-el-content"></slot>
</div>
</div>
`;
const contentElement = /** @type {HTMLElement} */ (
mainElement.querySelector('#light-el-content')
);
const dialogWrapperElement = /** @type {HTMLElement} */ (
shadowRoot.querySelector('#dialog-wrapper')
);
await fixture(html`${mainElement}`);

expect(deepContains(dialogWrapperElement, contentElement)).to.be.true;
});
});

0 comments on commit 6202f13

Please sign in to comment.