Skip to content

Commit a0faf69

Browse files
authored
docs: adjust ByTestId misleading warnings; add guidelines about accessibilityHint (#542)
* docs: remove byTestId misleading warnings * change caution to warning, mention principles and accessibility guideline * promote new aliases in docs example * rephrase
1 parent 7ba3152 commit a0faf69

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

website/docs/MigrationV2.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ In v2 we fixed this inconsistency, which may result in failing tests, if you rel
113113
- replace `testID` with proper `accessibilityHint` or `accessibilityLabel` if it benefits the user
114114
- use safe queries like `*ByText` or `*ByA11yHint`
115115

116-
:::caution
117-
In general, you should avoid `*byTestId` queries when possible. Use queries that check things that the user can interact with. Like `*ByText` or `*ByPlaceholderText` or accessibility queries (e.g. `*ByA11yHint`, `*ByA11yLabel`).
118-
:::
119-
120116
## Deprecated `flushMicrotasksQueue`
121117

122118
We have deprecated `flushMicrotasksQueue` and plan to remove it in the next major. We have better alternatives available for helping you write async tests – `findBy` async queries and `waitFor` helper.

website/docs/Queries.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ const { getByTestId } = render(<MyComponent />);
107107
const element = getByTestId('unique-id');
108108
```
109109

110-
:::caution
111-
Please be mindful when using these API and **treat it as an escape hatch**. Your users can't interact with `testID` anyhow, so you may end up writing tests that provide false sense of security. Favor text and accessibility queries instead.
110+
:::info
111+
In the spirit of [the guiding principles](https://testing-library.com/docs/guiding-principles), it is recommended to use this only after the other queries don't work for your use case. Using `testID` attributes do not resemble how your software is used and should be avoided if possible. However, they are particularly useful for end-to-end testing on real devices, e.g. using Detox and it's an encouraged technique to use there. Learn more from the blog post ["Making your UI tests resilient to change"](https://kentcdodds.com/blog/making-your-ui-tests-resilient-to-change).
112112
:::
113113

114114
### `ByA11yLabel`, `ByAccessibilityLabel`, `ByLabelText`
@@ -122,8 +122,8 @@ Returns a `ReactTestInstance` with matching `accessibilityLabel` prop.
122122
```jsx
123123
import { render } from '@testing-library/react-native';
124124

125-
const { getByA11yLabel } = render(<MyComponent />);
126-
const element = getByA11yLabel('my-label');
125+
const { getByLabelText } = render(<MyComponent />);
126+
const element = getByLabelText('my-label');
127127
```
128128

129129
### `ByA11yHint`, `ByAccessibilityHint`, `ByHintText`
@@ -137,10 +137,14 @@ Returns a `ReactTestInstance` with matching `accessibilityHint` prop.
137137
```jsx
138138
import { render } from '@testing-library/react-native';
139139

140-
const { getByA11yHint } = render(<MyComponent />);
141-
const element = getByA11yHint('my-hint');
140+
const { getByHintText } = render(<MyComponent />);
141+
const element = getByHintText('Plays a song');
142142
```
143143

144+
:::info
145+
Please consult [Apple guidelines on how `accessibilityHint` should be used](https://developer.apple.com/documentation/objectivec/nsobject/1615093-accessibilityhint).
146+
:::
147+
144148
### `ByA11yStates`, `ByAccessibilityStates`
145149

146150
> getByA11yStates, getAllByA11yStates, queryByA11yStates, queryAllByA11yStates

0 commit comments

Comments
 (0)