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

Add .toBeAccessible() #538

Open
simon-abbott opened this issue Sep 21, 2023 · 0 comments
Open

Add .toBeAccessible() #538

simon-abbott opened this issue Sep 21, 2023 · 0 comments

Comments

@simon-abbott
Copy link

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.

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

No branches or pull requests

1 participant