Skip to content

poc for getting/querying by title #34

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

Merged
merged 2 commits into from
May 5, 2018

Conversation

lgandecki
Copy link
Collaborator

@lgandecki lgandecki commented May 5, 2018

What:

Add ability to get/query by title, basic test coverage for now

Why:

Here comes my question, I've been seeing this pattern quite a bit:
https://github.com/meteor/todos/blob/react/imports/ui/components/ListHeader.jsx#L162

I wanted to learn your thinking here - are those antipatterns? I'm rewriting above example app by the Meteor guys to Apollo backend/frontend, while using cypress-testing-library and react-testing-library to drive the work.

I'm not sure if I have any other way of accessing elements like that.

I could rewrite places like that to use img with alt instead, but I'm trying to keep the components as similar to the original ones as possible (so it will be easier to compare between meteor and apollo)

How:

Checklist:

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

@lgandecki
Copy link
Collaborator Author

One more thing! In the react-testing-library I just add custom selectors as I go, some for a high level functionality (like this - getByTitle, or getByValue), some for higher level ( getDeleteTodo ), it works beautifully and seamlessly, but when I go to cypress I can't reuse them. It would be nice to expose this:
https://github.com/kentcdodds/cypress-testing-library/blob/master/src/index.js#L8
so people could add their own custom getters the way you have done there :) Right now I just copied and pasted this code to my codebase, but I'm obviously not very happy with that solution.

Is this something you would be willing to take a PR for?

@kentcdodds
Copy link
Member

are those antipatterns?

No, I think those are ok, if that's what the design calls for 👌

I'm in favor of adding this query 👍

It would be nice to expose this:
https://github.com/kentcdodds/cypress-testing-library/blob/master/src/index.js#L8

Yep, feel free to open a PR

@lgandecki
Copy link
Collaborator Author

Cool, thanks! Next one I needed to add manually that seems universal was getByValue. What do you think about that one?

In case of that specific rewrite I'm doing - all the listed todos are inputs with values. They get automatically updated when you click and change their value. unfortunately, getByText doesn't work in that case. Using placeholder doesn't make too much sense - it would have to be generic ("todo") instead of the specific todo text. And, obviously, I'd rather not add testids there, since all I have is already visible from the point of view of the user :)

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.

Thanks! This is great 👏

@kentcdodds kentcdodds merged commit 5fe849f into testing-library:master May 5, 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 :)

@kentcdodds
Copy link
Member

🎉 This PR is included in version 1.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lgandecki
Copy link
Collaborator Author

Thanks @kentcdodds !

I think you missed my comment by accident - what would you think about a similar PR for getByValue (reasons in the comment above)?

@kentcdodds
Copy link
Member

Yes, I suppose a getByValue also makes sense. In general, I'm in favor of selectors that resemble how users find elements on the page, or (less optimal) how screen readers find elements on a page.

@lgandecki lgandecki mentioned this pull request May 6, 2018
4 tasks
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