Skip to content

getByText doesn't find nodes that are <input type="submit" value="XXX"> #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
julienw opened this issue Dec 17, 2018 · 3 comments · Fixed by testing-library/dom-testing-library#185

Comments

@julienw
Copy link

julienw commented Dec 17, 2018

I use a code that contains an submit button like this:

        <input
          className="compareHome-submit-button"
          type="submit"
          value="Retrieve profiles"
        />

With react-testing-library I want to get it using for example getByText('Retrieve profiles'), which I expect to work because the text 'Retrieve profiles' is actually seen by users.

But this doesn't work and fails with this error:

    Unable to find an element with the text: Retrieve profiles. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Is this error expected in this case? I don't find an easy way to get to the submit button and have to use a matcher function instead...

@kentcdodds
Copy link
Member

Interesting. I think that the query should be updated to account for this case.

The change will actually be pretty simple in this file: https://github.com/kentcdodds/dom-testing-library/blob/master/src/get-node-text.js

We'll want a test for this as well. Would you be willing to make that contribution?

@julienw
Copy link
Author

julienw commented Dec 17, 2018

Yes, I'm interested in fixing this, but realistically I won't be able to get to it before Thursday or Friday. And if you see nothing before Friday it means it won't be before next year :-) (Precising this in case anybody wants to work on it before this).

@julienw
Copy link
Author

julienw commented Dec 20, 2018

I realize that <input type="button"> is concerned too.

julienw added a commit to julienw/react-testing-library that referenced this issue Dec 20, 2018
julienw added a commit to julienw/react-testing-library that referenced this issue Dec 20, 2018
kentcdodds pushed a commit to testing-library/dom-testing-library that referenced this issue Dec 20, 2018
…it` (#185)

* Make getByText support inputs where type is either `button` or `submit`

Closes testing-library/react-testing-library#248

* change quotes
lucbpz pushed a commit to lucbpz/react-testing-library that referenced this issue Jul 26, 2020
qijixin2 pushed a commit to qijixin2/dom-testing-library that referenced this issue Aug 26, 2022
…it` (#185)

* Make getByText support inputs where type is either `button` or `submit`

Closes testing-library/react-testing-library#248

* change quotes
DaiHai027 pushed a commit to DaiHai027/Dom-Testing-Library that referenced this issue Aug 19, 2024
…it` (#185)

* Make getByText support inputs where type is either `button` or `submit`

Closes testing-library/react-testing-library#248

* change quotes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants