Skip to content
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

fix(ByLabelText): improve error message when label is associated with… #720

Conversation

ipap360
Copy link
Contributor

@ipap360 ipap360 commented Jul 27, 2020

… non-labellable elements (#716)

What:

Add a more specific error message whenever getByLabelText/getAllByLabelText cannot find an associated element because the element is non-labellable.

Why:

The generic error message wasn't clear on why it was failing and whether this was changed on purpose (given that it was previously working).

How:

Whenever a label exists but no form control association is found, do an additional check for any other elements associated with the label via the "for" attribute. If there are, print specific error messages on why the query is failing and how to resolve this issue.

Checklist:

  • Documentation added to the
    docs site N/A
  • Tests
  • Typescript definitions updated N/A
  • Ready to be merged

My very first open source contribution 😊
Really happy that it is for a great project that I rely so much on 🥳

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 27, 2020

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 bc54893:

Sandbox Source
kentcdodds/react-testing-library-examples Configuration

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Looks great to me! Just need to figure out the coverage issue. Looks like we may be missing a branch of code in the tests.

@codecov
Copy link

codecov bot commented Jul 29, 2020

Codecov Report

Merging #720 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #720   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines          635       646   +11     
  Branches       165       168    +3     
=========================================
+ Hits           635       646   +11     
Impacted Files Coverage Δ
src/queries/label-text.js 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 26bf006...bc54893. Read the comment docs.

@ipap360
Copy link
Contributor Author

ipap360 commented Jul 29, 2020

Looks great to me! Just need to figure out the coverage issue. Looks like we may be missing a branch of code in the tests.

Sorry about that. Changed an existing test slightly to cover this branch too. 😇

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks!

@kentcdodds kentcdodds merged commit 92f03c5 into testing-library:master Jul 29, 2020
@kentcdodds
Copy link
Member

@all-contributors please add @ipap360 for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @ipap360! 🎉

@kentcdodds
Copy link
Member

🎉 This PR is included in version 7.21.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ipap360 ipap360 deleted the pr/get-by-label-text-non-labellable-elements branch July 29, 2020 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants