Thre should be a query that works for <button> or <input type=button value="">
See original GitHub issueDescribe the feature you’d like:
There should be a query that works for both these elements :
<button>Click Me</button>
<input type="button" value="Click Me" />
Currently, getByDisplayValue("Click Me")
will find the input but not the button, and getByText("Click Me")
is the opposite. There is no way to write a test that will stay green if i refactor one into the other (Assuming that for whatever reason I can’t use getByRole or other queries)
Suggested implementation:
getByText finding the input is counter-intuitive I think, so in my opinion the best way would be to change the getByDisplayValue
query so that it works with button elements.
Describe alternatives you’ve considered:
There are many workarounds and alternatives, but they rely on using less specific queries, or queries that make the tests less close to what a user would do, which is the apposite of what I’m trying to do if I’m using testing-library.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Thanks ! I realise what I want is already the way it works 😄
I misread the documentation there : https://testing-library.com/docs/queries/bytext, missed the line
I also was not aware of the way getByRole works.
Should have tried before filing the issue 😃
getByRole actually queries by implicit roles (for instance, a Button element has an implicit
button
role) - playground.