Skip to content

Add getAllByTestId & queryAllByTestId helper functions #20

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

Closed

Conversation

bahdcoder
Copy link

@bahdcoder bahdcoder commented Mar 24, 2018

What: Add new query capabilities for improved tests

  • getAllByTestId
  • queryAllByTestId

Why: These will include querying for multiple elements rendered in the dom
It will improve usability of the module.

add tests for queryAllByTestId functions
add tests for getAllByTestId function

How:

  • Added the respective functions in the queries.js file
  • Added tests for functions in the __tests__/element-queries.js file

Checklist:

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

**What**: Add new query capabilities for improved tests

- getAllByTestId
- queryAllByTestId

**Why**: These will include querying for multiple elements rendered in the dom
It will improve usability of the module.

add tests for queryAllByTestId functions
add tests for getAllByTestId function

**How**:

- Added the respective functions in the `queries.js` file
- Added tests for functions in the `__tests__/element-queries.js` file

**Checklist**:

* [ ] Documentation
* [x] Tests
* [x] Ready to be merged
* [x] Added myself to contributors table
@bahdcoder bahdcoder changed the title feat(add getAllByTestId & queryAllByTestId functions) Add getAllByTestId & queryAllByTestId helper functions Mar 24, 2018
@codecov
Copy link

codecov bot commented Mar 24, 2018

Codecov Report

Merging #20 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #20   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines          53     58    +5     
  Branches       13     14    +1     
=====================================
+ Hits           53     58    +5
Impacted Files Coverage Δ
src/queries.js 100% <100%> (ø) ⬆️

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 12c7ed1...7060a98. Read the comment docs.

@kentcdodds
Copy link
Member

Thanks for this! However I'm not sure I want to add it. A test ID should normally be unique and identify a single element. I'm not sure if a good use case for having multiple elements with the same ID. There's documentation in the README FAQ about how to make it unique for elements that you iterate over and I feel like that's enough. What do you think?

@bahdcoder
Copy link
Author

bahdcoder commented Mar 24, 2018

Hey @kentcdodds , Didn't see the README FAQ on iterated items earlier, but now that I have, I totally agree with you about test ID being unique (Even when raising the pull request I had a very quiet doubt in my mind about this).
I guess this should be closed then. 👍

Just a little question in my mind. What if I needed to get all the iterated items and count them ? How do you suggest this could be done ? I was thinking using css regular expression attribute matching ?

One last thing, you are a great motivator of mine, and thanks to you (egghead tutorials and blog posts) I have been able to raise my very first ever pull request to an open source project. I'm grateful for the opportunity. 🙇 Thanks a lot for your time.

@lgandecki
Copy link
Collaborator

@bahdcoder how about set a testid on a parent of elements you want to count, and then count the children :-)

@kentcdodds
Copy link
Member

Hi friends 👋

Thanks for the discussion here. I think based on this discussion I'll go ahead and close this PR. Maybe someday it'll resurface again. But for now it's easier to say "no" now and bring it back up again in the future than to say "yes" and try to remove it in the future.

Thanks!

@kentcdodds kentcdodds closed this Mar 27, 2018
julienw pushed a commit to julienw/react-testing-library that referenced this pull request Dec 20, 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.

3 participants