Skip to content

Lists elements that matched multiple error #678

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

Conversation

jacobparis
Copy link
Collaborator

@jacobparis jacobparis commented Jun 28, 2020

What:

This PR adds the found elements to the log output of the MultipleError

Current error

TestingLibraryElementError: Found multiple elements with the role "definition"

New error

TestingLibraryElementError: Found multiple elements with the role "definition"
    <dd
      aria-labelledby="uid-4-propertyValue"
      class="mb-0 text-size-large"
    >
      565000           
    </dd>
    <dd
      aria-labelledby="uid-4-appraisedValue"
      class="mb-0 text-size-large"
    >
      None         
    </dd>
    <dd
      aria-labelledby="uid-4-appraisedValue"
      class="mb-0 text-size-large"
    >
      2240 sqft         
    </dd>

Why:

It's not always immediately obvious which elements are conflicting, and since dom-testing-library needs to find them in order to know there are multiples it makes sense to expose that to the user

How:

I'm quite certain this is not the correct implementation of this feature, but I wanted to trial it out before investing too much time. If it's something deemed worthy of inclusion, I'd appreciate a little guidance on how to structure this (possibly a new wrapQuery type function) in a way that's idiomatic to the codebase

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 Jun 28, 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 ca6ceb3:

Sandbox Source
agitated-darkness-kgkbj Configuration

@codecov
Copy link

codecov bot commented Jun 28, 2020

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #678   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines          602       603    +1     
  Branches       151       151           
=========================================
+ Hits           602       603    +1     
Impacted Files Coverage Δ
src/query-helpers.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 3c262fd...ca6ceb3. Read the comment docs.

@kentcdodds
Copy link
Member

I definitely feel like this would improve the error message. I'd love to find a way to do it that is backwards compatible. We can improve the API in the next major version bump.

@jacobparis
Copy link
Collaborator Author

I think ideally it belongs in the getMultipleElementsFoundError function, but since that requires an API change, directly in makeSingleQuery is the next best place

I've pushed that change (no longer breaking) and an accompanying test

nickserv
nickserv previously approved these changes Jun 28, 2020
kentcdodds
kentcdodds previously approved these changes Jun 28, 2020
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.

Love it 👍

@kentcdodds
Copy link
Member

I think your other PR triggered merge conflicts. Could you fix those please?

@jacobparis jacobparis dismissed stale reviews from kentcdodds and nickserv via b339616 June 28, 2020 17:42
@jacobparis
Copy link
Collaborator Author

Wow git really mangled those together

All resolved now 🙏

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 👍

@kentcdodds kentcdodds merged commit 639294c into testing-library:master Jun 28, 2020
@kentcdodds
Copy link
Member

Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the other/MAINTAINING.md and CONTRIBUTING.md files (specifically the bit about the commit messages and the git hooks) and familiarize yourself with the code of conduct (we're using the contributor covenant). You might also want to watch the repo to be notified when someone files an issue/PR. Please continue to make PRs as you feel the need (you can make your branches directly on the repo rather than your fork if you want). Thanks! And welcome to the team :)

@kentcdodds
Copy link
Member

🎉 This PR is included in version 7.19.0 🎉

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants