-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Recent danger button update breaks react testing library getRyRole #8374
Comments
One temporary workaround is to use a regex for the name property. This isn't optimal though, b/c it requires the user to know the inner structure of the button and as we've seen, that can change. |
Hi @finken2! 👋 I believe #8222 added in the I believe the original test could be updated to use the regex as you mentioned, or to include Let me know if I'm misunderstanding how RTL resolves what the text of something is, it's been a while since I've taken a look at how that works 👀 |
@joshblack RTL allows you to specify "name" when using getByRole, which should go through the right assistive technology flow of looking at labeledby, aria-label, etc, eventually landing on text node in the button. Since we don't have any of the other labeling, it ends up looking in the body and doesn't match. I agree, we can work around it with the regex, but that's really error-prone and not how it should work. I'd rather add aria-label to the Button if we can. |
@finken2 that's awesome, based on that it seems like doing When |
@joshblack yep, that does work. Good point about the appending w/ aria-label too. Once we put that "danger" description in there, we're probably stuck with something unintuitive for the test. Thanks for talking through it. |
In the most recent carbon react build (7.32.1), a span was added inside
<Button>
when it's a danger button. From the storybook:The proper way to use react-testing-library is to use
getByRole('button', {name: 'blah'});
With this update, danger buttons are no longer found.https://testing-library.com/docs/queries/byrole
One possible fix is adding a aria-label to the Button tag, but there's other possibilities.
The text was updated successfully, but these errors were encountered: