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

Add queryAll/getAll methods #28

Merged
merged 8 commits into from
Apr 24, 2018

Conversation

alexkrolick
Copy link
Collaborator

@alexkrolick alexkrolick commented Apr 22, 2018

What:

Adds "all" methods for:

  • byAltText
  • byTestId

Why:

#27

How:

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Sidenote

If these getAll methods are added, the queryBy methods seem kind of redundant - instead of checking if queryBy returns null, you can check if getAll is [].

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.

I'm thinking that it would be good to actually have an *All* version for every query/get method for consistency.

And I'm thinking that we could probably have the *All* methods be the base and the existing methods just use those and return the first element to simplify the implementation.

What do you think?

Also, we'll want to make sure to document the existence of the *All* methods.

@alexkrolick
Copy link
Collaborator Author

alexkrolick commented Apr 23, 2018

I'm thinking that it would be good to actually have an All version for every query/get method for consistency.

Yep, just wanted to start with a few cases for review.

And I'm thinking that we could probably have the All methods be the base and the existing methods just use those and return the first element to simplify the implementation.

Yeah. Would the queryBy methods continue to be supported (ie if (result.length === 0) return null) or phased out?

Also, we'll want to make sure to document the existence of the All methods.

Yep.

Also, CI failed. Should I go for 100% branch coverage?

@kentcdodds
Copy link
Member

Yes, let's do this with no breaking changes.

Yes, please maintain 100% code coverage 👍

@alexkrolick
Copy link
Collaborator Author

alexkrolick commented Apr 24, 2018

OK, 🍏

  • Added queryAll methods for everything
  • Reimplemented query APIs using queryAll
  • Aliased getAll to queryAll (they are the same)
  • Added tests for the array methods; most of the code is actually executed in tests for the get methods.
  • Added docs

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.

I didn't have time to review everything, but I think we want the getAll* APIs to throw an error if there are no matching elements.

@alexkrolick
Copy link
Collaborator Author

✅ Changed getAll to throw the same errors as the get methods

src/queries.js Outdated
container,
)}`,
)
throw noMatchingAltText(container, alt)
Copy link
Member

Choose a reason for hiding this comment

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

What if instead of creating these error functions we had the getBy* functions use the getAllBy* functions? Perhaps using firstResultOrNull.

Sorry, I still haven't reviewed all the PR but this is just something else I noticed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep that makes sense!

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.

Wow, this is so good. Thank you so much for the contribution! 🎉

@kentcdodds kentcdodds merged commit 6e0c752 into testing-library:master Apr 24, 2018
@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 :)

@alexkrolick alexkrolick deleted the feature/queryAll branch April 24, 2018 19:52
@kentcdodds
Copy link
Member

🎉 This PR is included in version 1.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

alexkrolick pushed a commit to alexkrolick/dom-testing-library that referenced this pull request Sep 13, 2018
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 this pull request may close these issues.

2 participants