Skip to content

test: cover aria-labelledby referencing a slot in shadow DOM - #5271

Merged
straker merged 3 commits into
developfrom
chut/4335-slot-labelledby-regression
Aug 4, 2026
Merged

test: cover aria-labelledby referencing a slot in shadow DOM#5271
straker merged 3 commits into
developfrom
chut/4335-slot-labelledby-regression

Conversation

@chutchins25

Copy link
Copy Markdown
Contributor

Adds a regression test for #4335, where axe.run threw TypeError: Cannot read properties of undefined (reading 'props') when a <section>'s aria-labelledby referenced 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 develop by the move to getAccessibleRefs for 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 no lib/ 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">), runs axe.run, and asserts:

  1. it does not throw,
  2. no result carries the Cannot read properties error, and
  3. the shadow DOM content is actually evaluated (guards against a silent no-op).

Why all rules instead of just aria-allowed-role

The original stack trace ran through aria-allowed-rolegetElementUnallowedRoles. On current develop, aria-allowed-role is 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 on axe.run for 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

Regression test for #4335 — computing the accessible name of a section
whose aria-labelledby points at an untracked <slot> no longer throws
"Cannot read properties of undefined" (fixed by the getAccessibleRefs
migration).

Closes #4335

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-labelledby idref 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 ensuring axe.run succeeded. If the run throws, the failure here will be a misleading TypeError rather than the regression signal. Add the same runError/results guards before accessing results.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.

Comment thread test/integration/full/aria-labelledby-slot/aria-labelledby-slot.js Outdated
Assert runError is null before dereferencing results, so a thrown
axe.run surfaces the real error instead of a secondary TypeError.
@chutchins25
chutchins25 marked this pull request as ready for review July 31, 2026 12:40
@chutchins25
chutchins25 requested a review from a team as a code owner July 31, 2026 12:41
@chutchins25
chutchins25 requested a review from straker July 31, 2026 12:41

@straker straker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@chutchins25

Copy link
Copy Markdown
Contributor Author

Good call — moved it to a unit test in test/commons/aria/arialabelledby-text.js, which asserts arialabelledbyText returns '' for an aria-labelledby that references a <slot> in the same shadow root (where the throw used to occur). Removed the full integration test. Re-requesting review.

@chutchins25
chutchins25 requested a review from straker August 4, 2026 18:20
@straker
straker merged commit 3784048 into develop Aug 4, 2026
23 checks passed
@straker
straker deleted the chut/4335-slot-labelledby-regression branch August 4, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

axecore error Cannot read properties of undefined

3 participants