question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
BenoitAvertycommented, Sep 30, 2021

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

It also works with inputs whose type attribute is either submit or button

I also was not aware of the way getByRole works.

Should have tried before filing the issue 😃

1reaction
afontcucommented, Sep 30, 2021

getByRole needs the “role” attribute to be present. Unfortunately it’s not always the case.

getByRole actually queries by implicit roles (for instance, a Button element has an implicit button role) - playground.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<input type="button"> - HTML: HyperText Markup Language
Button with a value. An <input type="button"> elements' value attribute contains a string that is used as the button's label.
Read more >
Value from input type="button" isn't being added to database
Seeing that you are unable to echo $_POST['quiz_start'] that means your value is not actually set. This is because when you use a...
Read more >
Solved: Re: Prevent any processing until Submit button was...
The simpleXML submit button is horribly broken and for complex usecases, cannot be made to work. Try this dahsboard's no-JavaScript approach instead:
Read more >
HTML Form – Input Type and Submit Button Example
In this tutorial, we will explore the HTML form element, the various input types it takes, and how to create a submit button...
Read more >
Button Type In HTML: Here's Why You Should Always Declare ...
Button Types · submit — Submits the current form data. (This is default.) · reset — Resets data in the current form. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found