diff --git a/packages/calcite-components/src/components/tabs/tabs.e2e.ts b/packages/calcite-components/src/components/tabs/tabs.e2e.ts index a1831b1ec82..28b7021897b 100644 --- a/packages/calcite-components/src/components/tabs/tabs.e2e.ts +++ b/packages/calcite-components/src/components/tabs/tabs.e2e.ts @@ -205,29 +205,12 @@ describe("calcite-tabs", () => { await page.waitForChanges(); - const finalSelectedItem = await page.evaluate( - async (templateHTML: string): Promise<{ tabTitle: string; tab: string }> => { - const wrapperName = "tab-wrapping-component"; - - async function waitForAnimationFrames(count: number): Promise { - async function frame() { - if (count > 0) { - await new Promise((resolve) => requestAnimationFrame(resolve)); - count--; - await frame(); - } - } - - await frame(); - } - + const wrapperName = "tab-wrapping-component"; + await page.evaluate( + async (wrapperName, templateHTML: string): Promise => { customElements.define( wrapperName, class extends HTMLElement { - constructor() { - super(); - } - connectedCallback(): void { this.attachShadow({ mode: "open" }).innerHTML = templateHTML; } @@ -235,24 +218,21 @@ describe("calcite-tabs", () => { ); document.body.innerHTML = `<${wrapperName}>`; - await waitForAnimationFrames(2); - - const wrapper = document.querySelector(wrapperName); - - wrapper.shadowRoot.querySelector("#title-2").click(); - - const tabTitle = wrapper.shadowRoot.querySelector("calcite-tab-title[selected]").id; - await waitForAnimationFrames(2); - - const tab = wrapper.shadowRoot.querySelector("calcite-tab[selected]").id; - return { tabTitle, tab }; }, + wrapperName, wrappedTabTemplateHTML, ); await page.waitForChanges(); - expect(finalSelectedItem.tabTitle).toBe("title-2"); - expect(finalSelectedItem.tab).toBe("tab-2"); + const nestedTabTitle2 = await page.find(`${wrapperName} >>> #title-2`); + await nestedTabTitle2.click(); + await page.waitForChanges(); + + const nestedSelectedTabTitle = await page.find(`${wrapperName} >>> calcite-tab-title[selected]`); + const nestedSelectedTab = await page.find(`${wrapperName} >>> calcite-tab[selected]`); + + expect(nestedSelectedTabTitle.id).toBe("title-2"); + expect(nestedSelectedTab.id).toBe("tab-2"); }); it("item selection should work with nested tabs", async () => {