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

feat: Enhance ByText error with selector #1159

Merged
merged 3 commits into from
Oct 8, 2022
Merged

feat: Enhance ByText error with selector #1159

merged 3 commits into from
Oct 8, 2022

Conversation

raplemie
Copy link
Contributor

@raplemie raplemie commented Aug 18, 2022

What: fixes #1158

Why: The selector option behavior might not be well known by everyone reading the tests, and current test error output does not mention that additional requirement of the element being searched (which might be shown in the prettyDOM, similar reasonning to #450)

How: By adding a conditional to the error message genereated which have access to the used selector, and display it in the case it is not undefined (function called directly) and different from "*" (default selector for getByText)

Checklist:

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 18, 2022

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 7054c06:

Sandbox Source
react-testing-library-examples Configuration

@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Merging #1159 (7054c06) into main (a9a8cf2) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #1159   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines          996       998    +2     
  Branches       327       326    -1     
=========================================
+ Hits           996       998    +2     
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/queries/text.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

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. You've checked that docs were added but I don't see a PR to the docs page (https://github.com/testing-library/testing-library-docs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc+author%3Araplemie)?

@raplemie
Copy link
Contributor Author

raplemie commented Oct 3, 2022

Thanks. You've checked that docs were added but I don't see a PR to the docs page (https://github.com/testing-library/testing-library-docs/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc+author%3Araplemie)?

I checked the docs checkmark because it was "handled" as N/A, not added. The error messages are not documented in the docs, so it didnt seem to require a docs change, but since the PR been sleeping for a month I thought that maybe this was automated that it had to be checked for it to process any further.

I unchecked the box, but is there a section where error messages are documented so I can follow the style ? Or do we keep the documentation as is if there is no precedent in documenting the error messages text that are returning by a query ?

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.

Oh, I only glanced at this, saw documentation checked and thought it needed docs but docs were forgotten.

But this doesn't add selector to ByText. It just adds it to the error message. Thank you for clarifying 👍🏻

@eps1lon eps1lon changed the title feat: enhance byText error with selector feat: Enhance ByText error with selector Oct 8, 2022
@eps1lon eps1lon merged commit d1a57dd into testing-library:main Oct 8, 2022
@eps1lon
Copy link
Member

eps1lon commented Oct 8, 2022

@all-contributors add @raplemie for code

@allcontributors
Copy link
Contributor

@eps1lon

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

@github-actions
Copy link

github-actions bot commented Oct 8, 2022

🎉 This PR is included in version 8.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@raplemie raplemie deleted the pr/selector-in-errmsg branch October 11, 2022 20:11
@raplemie
Copy link
Contributor Author

Thanks for merging!

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.

Display provided selector in *ByText error message
3 participants