Closed
Description
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:
- text content of element referenced by
accessibilityLabelledBy
/aria-labelledby
prop accessbilityLabel
/aria-label
prop- 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,
options?: TextMatchOptions,
)
The matcher should:
- Validate that it is invoked on a host element
- When
expectedName
param is provided check if it matches element's accessible name - When
expectedName
is not provided check if element has accessible name
Each matcher should have a fairly comprehensive test suite.