test: cover aria-labelledby referencing a slot in shadow DOM - #5271
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a full integration regression test to ensure axe.run does not throw (and does not surface errored incomplete results) when aria-labelledby references a <slot> within the same shadow root, covering the scenario from #4335 and guarding against reintroducing the prior Cannot read properties of undefined (reading 'props') failure.
Changes:
- Add a new full integration test page that reproduces the shadow DOM +
<slot>aria-labelledbyidref scenario from #4335. - Add mocha assertions ensuring
axe.run('#host')succeeds, does not include the historical"Cannot read properties"error text, and actually evaluates shadow DOM content.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/integration/full/aria-labelledby-slot/aria-labelledby-slot.html | New integration fixture reproducing the shadow DOM <section aria-labelledby="foo"> + <slot id="foo"> setup from #4335. |
| test/integration/full/aria-labelledby-slot/aria-labelledby-slot.js | New mocha test running axe.run against the host element and asserting the regression does not reappear. |
Suppressed comments (1)
test/integration/full/aria-labelledby-slot/aria-labelledby-slot.js:33
- This test dereferences
results.*without first ensuringaxe.runsucceeded. If the run throws, the failure here will be a misleading TypeError rather than the regression signal. Add the samerunError/resultsguards before accessingresults.passes/violations/incomplete.
it('evaluates the shadow DOM content (guards against a no-op test)', () => {
const evaluated =
results.passes.length +
results.violations.length +
results.incomplete.length;
assert.isAbove(evaluated, 0);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Assert runError is null before dereferencing results, so a thrown axe.run surfaces the real error instead of a secondary TypeError.
straker
left a comment
There was a problem hiding this comment.
I think this test would be better in https://github.com/dequelabs/axe-core/blob/develop/test/commons/aria/arialabelledby-text.js as that is where the error would occur for the slot element previously.
Per review, the aria-labelledby -> slot regression belongs in test/commons/aria/arialabelledby-text.js (where the error occurred), not a full integration test. Add the unit test and remove the integration test.
|
Good call — moved it to a unit test in |
Adds a regression test for #4335, where
axe.runthrewTypeError: Cannot read properties of undefined (reading 'props')when a<section>'saria-labelledbyreferenced a<slot>in the same shadow root. The slot is not tracked in axe's virtual tree, so accessible-name computation dereferenced an undefined virtual node.Already fixed — this is a regression test
The underlying error is already resolved on
developby the move togetAccessibleRefsfor accessible-name idref lookups. Per review guidance (Steve / Wilco), the goal is only to guarantee the error stays fixed — not to add<slot>support. So this PR adds test coverage only; there are nolib/changes.The test
test/integration/full/aria-labelledby-slot/— a full integration test that builds Steve's exact repro (a shadow root with<section aria-labelledby="foo">+<slot id="foo">), runsaxe.run, and asserts:Cannot read propertieserror, andWhy all rules instead of just
aria-allowed-roleThe original stack trace ran through
aria-allowed-role→getElementUnallowedRoles. On currentdevelop,aria-allowed-roleis inapplicable to a role-less<section>, so a rule-scoped test there would be a no-op. Per Steve's note that axe-core 4.11.1 produced errored incomplete results onaxe.runfor this page, the test runs the full rule set — which I confirmed exercises the section (5 rules) and would have failed pre-fix.Closes #4335