diff --git a/packages/calcite-components/src/tests/commonTests/themed.ts b/packages/calcite-components/src/tests/commonTests/themed.ts index e3691930c2a..05ad1c14519 100644 --- a/packages/calcite-components/src/tests/commonTests/themed.ts +++ b/packages/calcite-components/src/tests/commonTests/themed.ts @@ -275,29 +275,29 @@ async function assertThemedProps(page: E2EPage, options: TestTarget): Promise { const searchInShadowDom = (node: Node): HTMLElement | SVGElement | Node | undefined => { - const { attribute, value } = context as { + const { attribute, value: valueToMatch } = context as { attribute: string; value: string; }; - if (node.nodeType === 1) { - const attr = (node as Element).getAttribute(attribute); - if (typeof value === "string" && attr === value) { - return node; - } - if (attr === value) { - return node; - } - if ((node as Element) && !attribute && !value) { - return node; + if (node.nodeType === 1) { + const el = node as Element; + const attrValue = el.getAttribute(attribute); + + if ( + (attribute === "class" && el.classList.contains(valueToMatch)) || + (attrValue === valueToMatch) || + (!attribute && !valueToMatch) + ) { + return el; } - } - if (node.nodeType === 1 && (node as Element).shadowRoot) { - for (const child of (node as Element).shadowRoot.children) { - const result = searchInShadowDom(child); - if (result) { - return result; + if (el.shadowRoot) { + for (const child of el.shadowRoot.children) { + const result = searchInShadowDom(child); + if (result) { + return result; + } } } } @@ -309,6 +309,7 @@ async function assertThemedProps(page: E2EPage, options: TestTarget): Promise((resolve) => { requestAnimationFrame(() => { const foundNode =