Skip to content

Commit df2e893

Browse files
committed
Fix aria-screen-readers spec
1 parent 8b2ce1a commit df2e893

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,5 @@ npm run lint # full lint suite
120120

121121
Astro, TypeScript, Lit, Tailwind CSS, Turso (libSQL), Sentry, Vercel, Playwright, Vitest, MJML, Workbox, GitHub Actions
122122

123-
test/e2e/specs/11-accessibility/aria-screen-readers.spec.ts
124123
test/e2e/specs/11-accessibility/axe.spec.ts
125124
test/e2e/specs/11-accessibility/high-contrast-wcag-compliance.spec.ts

test/e2e/specs/11-accessibility/aria-screen-readers.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ const getAccessibleNameCandidate = async (locator: Locator): Promise<string> =>
6262
})
6363
}
6464

65+
const isHiddenFromAssistiveTechnology = async (locator: Locator): Promise<boolean> => {
66+
return locator.evaluate((element): boolean => {
67+
return Boolean(element.closest('[aria-hidden="true"], [hidden], [inert]'))
68+
})
69+
}
70+
6571
const normalizeAccessibleName = (name: string): string => {
6672
return name.replace(/\s+/g, ' ').trim().toLowerCase()
6773
}
@@ -205,15 +211,22 @@ describe('ARIA and Screen Readers', () => {
205211
const inputs = page.page.locator(visibleFormControlSelector)
206212
const count = await inputs.count()
207213

208-
expect(count).toBeGreaterThan(0)
214+
let checkedCount = 0
209215

210216
for (let i = 0; i < count; i++) {
211217
const input = inputs.nth(i)
218+
if (await isHiddenFromAssistiveTechnology(input)) {
219+
continue
220+
}
221+
222+
checkedCount += 1
212223
await expect(input).toHaveAccessibleName(/\S+/)
213224

214225
const inputName = normalizeAccessibleName(await getAccessibleNameCandidate(input))
215226
expect(inputName.length).toBeGreaterThan(0)
216227
}
228+
229+
expect(checkedCount).toBeGreaterThan(0)
217230
}, true)
218231
})
219232

0 commit comments

Comments
 (0)