diff --git a/generate-act-tests.js b/generate-act-tests.js index 23d28a8..bc80173 100644 --- a/generate-act-tests.js +++ b/generate-act-tests.js @@ -113,7 +113,6 @@ const rulesToIgnore = [ "off6ek", "oj04fd", "ucwvc8", - "ye5d6e", "bf051a", ]; @@ -172,9 +171,9 @@ const parser = new DOMParser(); describe("[${ruleId}]${ruleName}", function () { it("${testcaseTitle} (${exampleURL})", async () => { - const document = parser.parseFromString(\`${html}\`, 'text/html'); + const el = parser.parseFromString(\`${html}\`, 'text/html'); - const results = (await scan(document.body)).map(({ text, url }) => { + const results = (await scan(el)).map(({ text, url }) => { return { text, url }; }); diff --git a/src/rules/area-alt.ts b/src/rules/area-alt.ts index 0bec230..3fc2509 100644 --- a/src/rules/area-alt.ts +++ b/src/rules/area-alt.ts @@ -5,7 +5,7 @@ const text = "Elements must only use allowed ARIA attributes"; const url = "https://dequeuniversity.com/rules/axe/4.4/area-alt?application=RuleDescription"; -export function areaAlt(el: Element): AccessibilityError[] { +export function areaAlt(el: Document | Element): AccessibilityError[] { const errors = []; for (const element of querySelectorAll("map area[href]", el)) { diff --git a/src/rules/aria-allowed-attr.ts b/src/rules/aria-allowed-attr.ts index 6390d1f..547713f 100644 --- a/src/rules/aria-allowed-attr.ts +++ b/src/rules/aria-allowed-attr.ts @@ -11,7 +11,7 @@ const ariaMappings: Record = { I: undefined, }; -export function ariaAllowedAttr(el: Element): AccessibilityError[] { +export function ariaAllowedAttr(el: Document | Element): AccessibilityError[] { const errors = []; const selector = Object.keys(ariaMappings).join(","); for (const element of querySelectorAll(selector, el)) { diff --git a/src/rules/aria-hidden-body.ts b/src/rules/aria-hidden-body.ts index 8c0b732..c58f125 100644 --- a/src/rules/aria-hidden-body.ts +++ b/src/rules/aria-hidden-body.ts @@ -4,12 +4,12 @@ const text = 'aria-hidden="true" must not be present on the document '; const url = "https://dequeuniversity.com/rules/axe/4.4/aria-hidden-body?application=RuleDescription"; -export function ariaHiddenBody(el: Element): AccessibilityError[] { - const element = el.ownerDocument.body; - if (element.getAttribute("aria-hidden") === "true") { +export function ariaHiddenBody(el: Document | Element): AccessibilityError[] { + const body = el instanceof Document ? el.body : el.ownerDocument.body; + if (body.getAttribute("aria-hidden") === "true") { return [ { - element, + element: body, text, url, }, diff --git a/src/rules/aria-roles.ts b/src/rules/aria-roles.ts index 2f7e6e6..6841ee0 100644 --- a/src/rules/aria-roles.ts +++ b/src/rules/aria-roles.ts @@ -24,7 +24,7 @@ const validRoles = [ "contentinfo", ]; -export default function (el: Element): AccessibilityError[] { +export default function (el: Document | Element): AccessibilityError[] { const errors = []; for (const element of querySelectorAll("[role]", el)) { const role = element.getAttribute("role"); diff --git a/src/rules/aria-tooltip-name.ts b/src/rules/aria-tooltip-name.ts index a2ee52a..fa9deec 100644 --- a/src/rules/aria-tooltip-name.ts +++ b/src/rules/aria-tooltip-name.ts @@ -31,7 +31,8 @@ function hasAccessibleText(el: Element): boolean { return true; } -export function ariaTooltipName(el: Element): AccessibilityError[] { +export function ariaTooltipName(el: Element | Document): AccessibilityError[] { + el = el instanceof Document ? el.documentElement : el; const errors = []; const tooltips = querySelectorAll("[role=tooltip]", el); if (el.matches("[role=tooltip]")) tooltips.push(el); diff --git a/src/rules/aria-valid-attr-value.ts b/src/rules/aria-valid-attr-value.ts index 8bc5451..bfd5247 100644 --- a/src/rules/aria-valid-attr-value.ts +++ b/src/rules/aria-valid-attr-value.ts @@ -82,7 +82,10 @@ function valid(el: Element, attribute: string, info: Info) { return false; } -export function ariaValidAttrValue(el: Element): AccessibilityError[] { +export function ariaValidAttrValue( + el: Element | Document, +): AccessibilityError[] { + el = el instanceof Document ? el.documentElement : el; const errors = []; const selector = Object.keys(ariaAttributes) .map((attributeName) => `[${attributeName}]`) diff --git a/src/rules/aria-valid-attr.ts b/src/rules/aria-valid-attr.ts index 0d32d1c..cd45830 100644 --- a/src/rules/aria-valid-attr.ts +++ b/src/rules/aria-valid-attr.ts @@ -11,7 +11,8 @@ const url = `https://dequeuniversity.com/rules/axe/4.4/${id}`; // TODO: Maybe use https://github.com/A11yance/aria-query for this? -export default function (el: Element): AccessibilityError[] { +export default function (el: Element | Document): AccessibilityError[] { + el = el instanceof Document ? el.documentElement : el; const errors = []; const selector = "*"; const elements = querySelectorAll(selector, el); diff --git a/src/rules/audio-caption.ts b/src/rules/audio-caption.ts index bcb2727..73b604a 100644 --- a/src/rules/audio-caption.ts +++ b/src/rules/audio-caption.ts @@ -5,7 +5,8 @@ const id = "audio-caption"; const text = "