Skip to content

feat(dom): toHaveAccessibleDescription - #174

Open
JDOM10 wants to merge 11 commits into
mainfrom
feat/dom-to-have-accessible-description
Open

feat(dom): toHaveAccessibleDescription#174
JDOM10 wants to merge 11 commits into
mainfrom
feat/dom-to-have-accessible-description

Conversation

@JDOM10

@JDOM10 JDOM10 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Added to Have Accessible Description.

@JDOM10 JDOM10 self-assigned this Jun 30, 2026
@JDOM10 JDOM10 added the enhancement New feature or request label Jun 30, 2026
@JDOM10
JDOM10 requested review from KeylaMunnoz and suany0805 and removed request for suany0805 June 30, 2026 15:51
Comment on lines +331 to +333
const expectation = expectedDescription instanceof RegExp
? `matching ${expectedDescription}`
: `"${expectedDescription}"`;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A minor suggestion here, to consider only constructing expectation when hasExpectedValue is true. Otherwise, it evaluates to the string "undefined" when no argument is passed, which isn't currently exposed but could be misleading or cause issues if this code changes later.

const expectation = hasExpectedValue
  ? expectedDescription instanceof RegExp
    ? `matching ${expectedDescription}`
    : `"${expectedDescription}"`
  : "";

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thanks!

@@ -327,25 +328,24 @@ export class ElementAssertion<T extends Element> extends Assertion<T> {
: desc === expectedDescription;
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking suggestion: this helper is clear as is, but it might be worth extracting it into helpers/accessibility.ts as we would end up adding other matchers in the future (e.g. toHaveAccessibleName) that could reuse the same matching logic 😸 let me know what you think !

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, sounds good!

@JDOM10
JDOM10 requested a review from KeylaMunnoz July 7, 2026 19:30
@JDOM10
JDOM10 requested a review from SbsCruz July 21, 2026 20:11
.join(" ");

return normalizeText(combinedText);
return expected instanceof RegExp

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.

why are we returning this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Because expected is RegExp | string — the check picks the right comparison at runtime and narrows the type so .test() type-checks.

@GonuDvc GonuDvc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approach is solid. Minor nit: this would benefit from a brief comment explaining why we skip validation for internal callers.

@@ -1,35 +1,24 @@
function normalizeText(text: string): string {
return text.replace(/\s+/g, " ").trim();
export function isValidAriaPressed(element: Element): boolean {

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.

good catch on cleanning up this helper 🚀


public toHaveDescription(expectedDescription?: RegExp | string): this {
const description = getAccessibleDescription(this.actual);
public toHaveAccessibleDescription(expectedDescription?: RegExp | string): this {

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.

what do you think about adding an alias to toHaveDescription

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll leave it as is. toHaveDescription is ambiguous: it reads like it's checking a description attribute or raw text content rather than the ARIA-computed description. This ticket is also moving toward covering the ARIA-related assertions, so the explicit name fits better.

@JDOM10
JDOM10 requested a review from suany0805 July 31, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants