Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: implement toHaveAccessibleValue Jest matcher #1485

Closed
mdjastrzebski opened this issue Sep 4, 2023 · 4 comments
Closed

feature: implement toHaveAccessibleValue Jest matcher #1485

mdjastrzebski opened this issue Sep 4, 2023 · 4 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@mdjastrzebski
Copy link
Member

mdjastrzebski commented Sep 4, 2023

Describe the Feature

toHaveAccessibleName is a Jest DOM matcher asserting that given element has certain accessible name: text content or a11y label.

RNTL already contains some code working with accessible name, namely *ByRole query accepts an optional name param. This matcher should compare expect name parameter with all of these:

  1. text content of element referenced by accessibilityLabelledBy / aria-labelledby prop
  2. accessbilityLabel / aria-label prop
  3. text content of given element

These should be evaluated in that particular order.

Possible Implementations

Proposed API:

export function toHaveAccessibleName(
  this: jest.MatcherContext,
  element: ReactTestInstance,
  expectedName?: TextMatch,
) 

The matcher should:

  1. Validate that it is invoked on a host element
  2. When expectedName param is provided check if it matches element's accessible name
  3. When expectedName is not provided check if element has accessible name

Each matcher should have a fairly comprehensive test suite.

Related Issues

#1454

@mdjastrzebski mdjastrzebski added help wanted Extra attention is needed good first issue Good for newcomers labels Sep 4, 2023
@tarunrajput
Copy link
Contributor

@mdjastrzebski, I'd like to implement this

@mdjastrzebski
Copy link
Member Author

@tarunrajput go ahead, it's yours now!

@mdjastrzebski mdjastrzebski changed the title feature: implement toHaveAccessibilityValue Jest matcher feature: implement toHaveAccessibleValue Jest matcher Sep 19, 2023
@mdjastrzebski
Copy link
Member Author

Resolved in #1496!

@mdjastrzebski
Copy link
Member Author

🎉 Release in version: v12.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants