Skip to content

Commit 537ed70

Browse files
committed
e2e(stencil): avoid strict mode violation by narrowing locator to section and first match
1 parent dc9cb01 commit 537ed70

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

showcases/e2e/default.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,27 @@ export const getDefaultScreenshotTest = ({
143143
await expect(byHeadingSection).toBeVisible({ timeout: 1500 });
144144
} catch {
145145
if (isStencil(showcaseEnv)) {
146-
// In stencil showcase, snapshot the component root or its labeled nav
147-
const wcComponent = page.locator('db-breadcrumb');
148-
const labeledNav = page.getByRole('navigation', {
146+
// In stencil showcase, snapshot the component within the section or its labeled nav
147+
const wcComponents = page.locator('db-breadcrumb');
148+
const labeledNavs = page.getByRole('navigation', {
149149
name: /breadcrumb/i
150150
});
151-
if (await wcComponent.count()) {
152-
target = wcComponent;
151+
const wcInSection = byHeadingSection.locator('db-breadcrumb');
152+
const navInSection = byHeadingSection.getByRole('navigation', {
153+
name: /breadcrumb/i
154+
});
155+
156+
if ((await wcInSection.count()) > 0) {
157+
target = wcInSection.first();
158+
await expect(target).toBeVisible({ timeout: 3000 });
159+
} else if ((await navInSection.count()) > 0) {
160+
target = navInSection.first();
161+
await expect(target).toBeVisible({ timeout: 3000 });
162+
} else if ((await wcComponents.count()) === 1) {
163+
target = wcComponents.first();
153164
await expect(target).toBeVisible({ timeout: 3000 });
154-
} else if (await labeledNav.count()) {
155-
target = labeledNav.first();
165+
} else if ((await labeledNavs.count()) > 0) {
166+
target = labeledNavs.first();
156167
await expect(target).toBeVisible({ timeout: 3000 });
157168
} else {
158169
// Fallback to main if component/nav not found

0 commit comments

Comments
 (0)