Add `.toBeAccessible()`
simon-abbott opened this issue · comments
Describe the feature you'd like:
testing-library exposes the isInaccessible
function, but using it to test for accessibility leads to a less than ideal testing experience. It would be nice if there was a first-class .toBeAccessible()
expectation we could use to check for accessible components.
Suggested implementation:
A simple wrapper around isInaccessible
, but with an actually useful error message.
Describe alternatives you've considered:
Alternative 1:
expect(isInaccessible(element)).toBe(false);
Pros: Works without modifying @testing-library/jest-dom
Cons:
- Bad error messages ("expected true to be false")
- Unclear intent due to double negative ("wait, do we want it to be inaccessible?")
- Unnecessarily verbose
Alternative 2:
Write a custom matcher.
Pros: Works without modifying @testing-library/jest-dom
Cons: Hard to make it work cleanly without needing to re-invent functions such as checkHtmlElement
Teachability, Documentation, Adoption, Migration Strategy:
Due to the simple nature of this matcher the docs should only need the bare minimum of an example and a link to the isInaccessible
docs.