Skip to content

Thre should be a query that works for <button> or <input type=button value=""> #1043

@BenoitAverty

Description

@BenoitAverty

Describe 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions