-
Notifications
You must be signed in to change notification settings - Fork 273
docs: Port 'How Should I Query?' guide from Native Testing Library #555
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
thymikee
merged 5 commits into
callstack:master
from
pplytas:docs/port-how-should-i-query-guide
Oct 12, 2020
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
71ba1f8
docs: Port How Should I Query guide
pplytas 8ca5062
fixup! docs: Port How Should I Query guide
pplytas b400cab
Update website/docs/HowShouldIQuery.md
thymikee 791e3e0
reword
thymikee fad4a9a
add getByAccessibilityState getByAccessibilityValue
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
id: how-should-i-query | ||
title: How Should I Query? | ||
--- | ||
|
||
## Priority | ||
|
||
Whatever you do, try to make your tests resemble real use cases. You'll only be confident with your tests if they work the way your users do. With that in mind, we recommend this order of priority: | ||
|
||
1. **Queries Users Can Interact With** | ||
- [`getByLabelText`](http://localhost:3000/react-native-testing-library/docs/api-queries#bya11ylabel-byaccessibilitylabel-bylabeltext): Your disabled users are counting on you, so this should likely be everywhere for their sake 😉 use it often, and if you aren't, maybe ask yourself why. | ||
- [`getByHintText`](http://localhost:3000/react-native-testing-library/docs/api-queries#bya11yhint-byaccessibilityhint-byhinttext): You should probably have an accessibility label that you can select by, but if for some reason you set this instead, it's safe to use. | ||
- [`getByPlaceholderText`](http://localhost:3000/react-native-testing-library/docs/api-queries#byplaceholdertext): Great for targeting a `TextInput` element to verify its content. | ||
- [`getByText`](http://localhost:3000/react-native-testing-library/docs/api-queries#bytext): Great for finding a `Text`, `Button`, or `Touchable` node. You'll probably use this one a lot. | ||
- [`getByDisplayValue`](http://localhost:3000/react-native-testing-library/docs/api-queries#bydisplayvalue): This is good because a user can see the value they type into a `TextInput` or whether a `Switch` is on or off. | ||
2. **Queries Users Can Interact With** | ||
- [`getByRole`](http://localhost:3000/react-native-testing-library/docs/api-queries#bya11yrole-byaccessibilityrole-byrole): If your app screens have good hierarchy, this may be a decent option for finding your elements. | ||
3. **Queries Users Don't Even Know About** | ||
- [`getByTestId`](http://localhost:3000/react-native-testing-library/docs/api-queries#bytestid): The user cannot see (or hear) these, so this is only recommended for cases where you can't match by text or it doesn't make sense | ||
thymikee marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.