Skip to content

Add getByPlaceholder query functionality #101

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 5 commits into from
Dec 22, 2018

Conversation

danahartweg
Copy link
Contributor

Summary

There is a helper that exists in react-testing-library to query inputs by their placeholder. This PR adds that support.

You could achieve this by querying for a placeholder prop, or querying for react native TextInputs manually and then checking their props, but it felt cleaner to have this contained in the testing library itself. It will also allow you to bypass any other instances that may have a placeholder prop that aren't TextInputs.

If we don't want to expand the surface of the library further, I completely understand that and am fine with this being closed. Just seems like it may be useful and save some time for several scenarios =)

Test plan

  • Render a TextInput with a placeholder prop
  • Query the test instance via getByPlaceholder for the input
  • Verify the test instance is found

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

I think it makes sense, especially that RTL has it already. Could you also add a TS test?

Co-Authored-By: danahartweg <dana.hartweg@gmail.com>
@thymikee
Copy link
Member

Mind adding a test here as well? https://github.com/callstack/react-native-testing-library/blob/master/typings/__tests__/index.test.tsx

@thymikee thymikee merged commit ee888f1 into callstack:master Dec 22, 2018
@thymikee
Copy link
Member

Thank you so much for this contribution!

@danahartweg
Copy link
Contributor Author

You're very welcome! As I use the library more, I'll be sure to keep a list of things that could be improved / added, and then get to discussing or implementing them.

@danahartweg danahartweg deleted the get-by-placeholder branch December 22, 2018 22:16
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