mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
feat: add getByPlaceholder query functionality (#101)
### 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 `TextInput`s 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 `TextInput`s. 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
This commit is contained in:
committed by
Michał Pierzchała
parent
5145a708db
commit
ee888f1dcd
@@ -52,6 +52,14 @@ A method returning a `ReactTestInstance` with matching text – may be a string
|
||||
|
||||
A method returning an array of `ReactTestInstance`s with matching text – may be a string or regular expression.
|
||||
|
||||
### `getByPlaceholder: (placeholder: string | RegExp)`
|
||||
|
||||
A method returning a `ReactTestInstance` for a `TextInput` with a matching placeholder – may be a string or regular expression. Throws when no matches.
|
||||
|
||||
### `getAllByPlaceholder: (placeholder: string | RegExp)`
|
||||
|
||||
A method returning an array of `ReactTestInstance`s for `TextInput`'s with a matching placeholder – may be a string or regular expression.
|
||||
|
||||
### `getByProps: (props: { [propName: string]: any })`
|
||||
|
||||
A method returning a `ReactTestInstance` with matching props object. Throws when no matches.
|
||||
|
||||
Reference in New Issue
Block a user