You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the issues of this repository and believe that this is not a duplicate.
Summary 💡
I have created a multi-select control using chips. You can see a live version here.
I am having a hard time testing it. Ideally each chip should behave like a button and the test should be able to target it using the button label (as recommended by the react-testing-library). However I can't do it with the generated markup. Here's a failed attempt at writing such a test. I can probably do this by adding a bunch of data-testid's, but that's really not recommended.
Examples 🌈
Here's how a chip is marked up in my control (original source):
As you can see, the selected chips get a check mark icon whereas unselected chips don't. I am trying to test exactly that. Using react-testing-library, it should be as simple as this:
As you can see, there is no easy way to select the chip by it's label. We probably need to use aria-labelledby in this case. Also the svg needs to be titled correctly to verify that we have a Check Icon and not something else. Here's the desired markup:
Summary 💡
I have created a multi-select control using chips. You can see a live version here.
I am having a hard time testing it. Ideally each chip should behave like a button and the test should be able to target it using the button label (as recommended by the react-testing-library). However I can't do it with the generated markup. Here's a failed attempt at writing such a test. I can probably do this by adding a bunch of
data-testid
's, but that's really not recommended.Examples 🌈
Here's how a chip is marked up in my control (original source):
As you can see, the selected chips get a check mark icon whereas unselected chips don't. I am trying to test exactly that. Using react-testing-library, it should be as simple as this:
Unfortunately, the generated markup does not make it as easy. Here's what is generated:
As you can see, there is no easy way to select the chip by it's label. We probably need to use
aria-labelledby
in this case. Also the svg needs to be titled correctly to verify that we have a Check Icon and not something else. Here's the desired markup:Is this something that can be achieved with no or minor modifications to the Chip component?
Motivation 🔦
I am trying to make sure that I can test my Material-UI components thoroughly using the guiding principles of the react-testing-library.
The text was updated successfully, but these errors were encountered: