Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (35 sloc) 2.22 KB
id title
How Should I Query?


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
    1. getByLabelText: 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.
    2. getByHintText: 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.
    3. getByPlaceholderText: Great for targeting a TextInput element to verify its content
    4. getByText: Great for finding a Text, Button, or Touchable node. You'll probably use this one a lot.
    5. getByDisplayValue: 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 Infer
    1. getByTitle: This isn't available on many elements, and there's likely a better way you can find the element you're looking for.
    2. getByRole: 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
    1. getByTestId: 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

Manual Queries

If you absolutely can't find a way to get the element you're looking for, you can use findAll as an escape hatch. Note that this is a bad practice and may introduce unpredictable behavior in your tests. It would likely be better to use a testID in most cases where you need to.

Also note, this utility still won't be able to find your app's components, it will only search for React Native core components. This library provides you no reasonable way to make an assertion on your components.

You can’t perform that action at this time.