Unable to get the name of the input when using getByRole while testing with testing-library Unable to get the name of the input when using getByRole while testing with testing-library reactjs reactjs

Unable to get the name of the input when using getByRole while testing with testing-library


You can see from the test output that your input element does not have aria-label. This causes the accessibility name to be an empty string "".

As per docs I think you want one of the following

<TextField inputProps={{ 'aria-label': 'code' }} />

or

<TextField label="code" />

Note

It is a good rule of thumb to try make it work without relying on aria properties first--and then using them if there is no other way. Read more


Useful links