-
Notifications
You must be signed in to change notification settings - Fork 403
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
Support for matching pressed state of toggle buttons #203
Comments
To be honest, this seems to be not too justified. The alternative way of checking it using I'm open to hear counter-arguments, in case I'm missing something. But if it's just a replacement for the corresponding |
adding a matcher that checks the accessibility of an element makes it easier for the dev to adopt and read test that has accessibility on the component. |
@jmvtrinidad I hear you. However, I am torn between what you said and an explicit goal in our own guiding principles stated in the README:
We need to draw the line somewhere. Our matchers need to do something that substitutes a cumbersome way of checking. If we go down this path suggested in this issue, then where does it end? If you go and check a list of existing aria attributes, then you'll see that we can soon end up having a myriad of custom matchers that are mere sugary syntax replacement for To illustrate the difference even further between what I'd consider good candidates over mere conveniences, consider a hypothetical matcher that I'd like and haven't made the time to propose or implement:
If this matcher would perform only the step (1) above, then I would not consider it worthy of implementing. If you wanted to check that the attribute is there, Hope this illustrates a bit the difference and what the reasoning is behind the objections to add a matcher such as |
@gnapse The example you have given totally makes sense, I will stop looking and use the |
Thanks. I'm going to go ahead and close this, which does not preclude the conversation to continue if someone still objects. Conclusion: using |
I understand wanting to make those library simpler and wanting to draw the line, but I wanna counter your argument with a bit more detail.
None of those are necessary because
I also understand why we have some of the current helpers:
Why I think
.not.toHaveAttribute(
'aria-pressed',
'true',
) |
I support adding the |
Thanks for insisting. Indeed, I've changed my mind. I now see value in this matcher due to the fact that it should also check if the element in question is a button. So the key here is: the custom matcher should respond with // <div data-testid="not-a-button" aria-pressed="true" />
expect(getByTestId('not-a-button')).toBePressed() // should fail While these other examples should pass: // <div role="button" aria-pressed="true">Div Button</div>
expect(getByRole('button', { name: 'Div Button' })).toBePressed() // should pass
// <button aria-pressed="true">Real Button</div>
expect(getByRole('button', { name: 'Real Button' })).toBePressed() // should pass @LucianHij yes, it'd be much appreciated if you contribute this. Thanks! |
Yes, I will try to do it. Do you have any link to how can I setup the project and do the implementation? @gnapse |
Sure, we do. Check out the "contributing" guide: https://github.com/testing-library/jest-dom/blob/main/CONTRIBUTING.md And let me know if you need more help or something's not clear. We can always improve that document if something could be better in it. |
Describe the feature you'd like:
Add a matcher for aria-pressed for checking button toggle states.
Suggested implementation:
A new matcher called
toBePressed
Describe alternatives you've considered:
An alternative solution would be to check for the attribute
aria-pressed="true"
oraria-pressed="mixed"
Teachability, Documentation, Adoption, Migration Strategy:
Docs entry:
toBePressed
This allows you to check if a form element is currently pressed.
An element is pressed if it is a button having a
aria-pressed="true"
oraria-pressed="mixed"
attribute.
Examples
The text was updated successfully, but these errors were encountered: