Skip to content

fix: support getting text of inputs of type reset #1011

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

Merged
merged 2 commits into from
Aug 25, 2021
Merged

fix: support getting text of inputs of type reset #1011

merged 2 commits into from
Aug 25, 2021

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Aug 19, 2021

What:

Currently doing screen.getByText('Reset') results in an error about being unable to find the text if you're testing for an input like so:

export const Form: React.FC<Props> = props => (
  <form onSubmit={props.onSubmit} onReset={props.onReset}>
    {props.children}
    <br />
    <input type="submit" value="Submit" />
    {props.onReset && <input type="reset" value="Reset" />}
  </form>
);

But this works fine if you try and select the "submit" input in the same manner: screen.getByText('Submit')

Why:

#185 added support for treating inputs of type submit & button as if they have text, but it left out reset which is the third "type" that has this behaviour.

How:

I've adjusted the query to include type=reset.

Checklist:

  • Documentation added to the
    docs site N/A I think (I couldn't find docs on this specific behaviour)
  • Tests
  • TypeScript definitions updated N/A
  • Ready to be merged

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 19, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 429d27e:

Sandbox Source
react-testing-library-examples Configuration

@eps1lon
Copy link
Member

eps1lon commented Aug 20, 2021

getByRole('button', { name: 'reset' }) should work. If not, please open an issue and fill out the issue template.

@eps1lon eps1lon closed this Aug 20, 2021
@eps1lon
Copy link
Member

eps1lon commented Aug 20, 2021

Just saw we do have support for "submit" 😕

@eps1lon eps1lon reopened this Aug 20, 2021
eps1lon
eps1lon previously approved these changes Aug 20, 2021
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eps1lon
Copy link
Member

eps1lon commented Aug 20, 2021

@G-Rath Please fix CI. The checks include the task that are run (https://github.com/testing-library/dom-testing-library/runs/3382484950). To start, run npm run format and commit the changes.

@codecov
Copy link

codecov bot commented Aug 25, 2021

Codecov Report

Merging #1011 (429d27e) into main (91b9dc3) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1011   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          916       916           
  Branches       285       285           
=========================================
  Hits           916       916           
Flag Coverage Δ
node-12 100.00% <100.00%> (ø)
node-14 100.00% <100.00%> (ø)
node-16 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/get-node-text.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91b9dc3...429d27e. Read the comment docs.

@eps1lon eps1lon merged commit 54b9a5f into testing-library:main Aug 25, 2021
@eps1lon eps1lon added the bug Something isn't working label Aug 25, 2021
@eps1lon
Copy link
Member

eps1lon commented Aug 25, 2021

Thanks!

@all-contributors add @G-Rath for code and test

@allcontributors
Copy link
Contributor

@eps1lon

I've put up a pull request to add @G-Rath! 🎉

@github-actions
Copy link

🎉 This PR is included in version 8.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants