Skip to content

Commit 51bd418

Browse files
docs: added warnings for *ByTestId queries (#305)
* Added usage notes for ByTestId queries * Update website/docs/Queries.md Co-authored-by: Michał Pierzchała <thymikee@gmail.com> * Update website/docs/Queries.md Co-authored-by: Michał Pierzchała <thymikee@gmail.com> Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent 58055d8 commit 51bd418

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

website/docs/Queries.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ const { getByTestId } = render(<MyComponent />);
9191
const element = getByTestId('unique-id');
9292
```
9393

94+
:::caution
95+
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.
96+
:::
97+
98+
:::danger
99+
Current implementation of `getByTestId` and `queryByTestId` has a serious flaw, which results in finding more IDs than there really would be present in native React host components. Fixing it may break some of your tests so we'll do it in next major release (v2). As a temporary workaround, please use `getAllByTestId('your-id')[0]` or `queryAllByTestId('your-id')[0]` or migrate off testing with testID, which is considered to be an escape hatch.
100+
:::
101+
94102
### `ByA11yLabel`, `ByAccessibilityLabel`
95103

96104
> getByA11yLabel, getAllByA11yLabel, queryByA11yLabel, queryAllByA11yLabel

0 commit comments

Comments
 (0)