diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..d2fc91bb1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cSpell.words": ["Pressable", "RNTL"] +} diff --git a/website/docs/HowShouldIQuery.md b/website/docs/HowShouldIQuery.md index 55af03e7f..24c137be5 100644 --- a/website/docs/HowShouldIQuery.md +++ b/website/docs/HowShouldIQuery.md @@ -3,19 +3,126 @@ id: how-should-i-query title: How Should I Query? --- -## Priority - -Based on the [Guiding Principles](https://testing-library.com/docs/guiding-principles), your test should resemble how users interact with your code (component, page, etc.) as much as possible. With this in mind, we recommend this order of priority: - -1. **Queries Accessible to Everyone** queries that reflect the experience of visual users as well as those that use assistive technology - - [`getByText`](https://callstack.github.io/react-native-testing-library/docs/api-queries#bytext): This is the number 1 method a user finds any visible text on interactive and non-interactive elements. - - [`getByDisplayValue`](https://callstack.github.io/react-native-testing-library/docs/api-queries#bydisplayvalue): Useful for the current value of a `TextInput`. - - [`getByPlaceholderText`](https://callstack.github.io/react-native-testing-library/docs/api-queries#byplaceholdertext): Only useful for targeting a placeholder of a `TextInput`. - - [`getByLabelText`](https://callstack.github.io/react-native-testing-library/docs/api-queries#bylabeltext): This can be used to query every element that is exposed in the accessibility tree as a label, usually when there's no visible text. - - [`getByHintText`](https://callstack.github.io/react-native-testing-library/docs/api-queries#bya11yhint-byaccessibilityhint-byhinttext): This can be used to query every element that is exposed in the accessibility tree as a hint. Make sure it also has a label set. - - [`getByAccessibilityState`](https://callstack.github.io/react-native-testing-library/docs/api-queries#bya11ystate-byaccessibilitystate): This can be used to query every element that is exposed in the accessibility tree as a state of an interactive element, like a checkbox. - - [`getByAccessibilityValue`](https://callstack.github.io/react-native-testing-library/docs/api-queries#bya11value-byaccessibilityvalue): This can be used to query every element that is exposed in the accessibility tree as a value on a range, like a slider. -2. **Queries Users Can Infer** - - [`getByRole`](https://callstack.github.io/react-native-testing-library/docs/api-queries#byrole): This can be used to query every element that is exposed in the accessibility tree as a role, like buttons or images. -3. **Test IDs** - - [`getByTestId`](https://callstack.github.io/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 +React Native Testing Library provides various query types, allowing great flexibility in finding views appropriate for your tests. At the same time, the number of queries might be confusing. This guide aims to help you pick the correct queries for your test scenarios. + +## Query parts + +Each query is composed of two parts: variant and predicate, which are separated by the `by` word in the middle of the query. + +Consider the following query: + +``` +getByRole() +``` + +For this query, `getBy*` is the query variant, and `*ByRole` is the predicate. + +## Query variant + +The query variants describe the expected number (and timing) of matching elements, so they differ in their return type. + +| Variant | Assertion | Return type | Is Async? | +| ----------------------------------------- | ----------------------------- | ------------------------------------------ | --------- | +| [`getBy*`](api-queries#get-by) | Exactly one matching element | `ReactTestInstance` | No | +| [`getAllBy*`](api-queries#get-all-by) | At least one matching element | `Array` | No | +| [`queryBy*`](api-queries#query-by) | Zero or one matching element | ReactTestInstance | null | No | +| [`queryAllBy*`](api-queries#query-all-by) | No assertion | `Array` | No | +| [`findBy*`](api-queries#find-by) | Exactly one matching element | `Promise` | Yes | +| [`findAllBy*`](api-queries#find-all-by) | At least one matching element | `Promise>` | Yes | + +Queries work as implicit assertions on the number of matching elements and will throw an error when the assertion fails. + +### Idiomatic query variants + +Idiomatic query variants clarify test intent and the expected number of matching elements. They will also throw helpful errors if assertions fail to help diagnose the issues. + +Here are general guidelines for picking idiomatic query variants: + +1. Use `getBy*` in the most common case when you expect a **single matching element**. Use other queries only in more specific cases. +2. Use `findBy*` when an element is not yet in the element tree, but you expect it to be there as a **result of some asynchronous action**. +3. Use `getAllBy*` (and `findAllBy*` for async) if you expect **more than one matching element**, e.g. in a list. +4. Use `queryBy*` only when element **should not exist** to use it together with e.g. [`not.toBeOnTheScreen()`](jest-matchers#tobeonthescreen) matcher. + +Avoid using `queryAllBy*` in regular tests, as it provides no assertions on the number of matching elements. You may still find it useful when building reusable custom testing tools. + +## Query predicate + +The query predicate describes how you decide whether to match the given element. + +| Predicate | Supported elements | Inspected props | +| ------------------------------------------------------- | ------------------ | ------------------------------------------------------------------------------------------- | +| [`*ByRole`](api-queries#by-role) | all host elements | `role`, `accessibilityRole`,
optional: accessible name, accessibility state and value | +| [`*ByLabelText`](api-queries#by-label-text) | all host elements | `aria-label`, `aria-labelledby`,
`accessibilityLabel`, `accessibilityLabelledBy` | +| [`*ByDisplayValue`](api-queries#by-display-value) | `TextInput` | `value`, `defaultValue` | +| [`*ByPlaceholderText`](api-queries#by-placeholder-text) | `TextInput` | `placeholder` | +| [`*ByText`](api-queries#by-text) | `Text` | `children` (text content) | +| [`*ByHintText`](api-queries#by-hint-text) | all host elements | `accessibilityHint` | +| [`*ByTestId`](api-queries#by-test-id) | all host elements | `testID` | + +### Idiomatic query predicates + +Choosing the proper query predicate helps better express the test's intent and make the tests resemble how users interact with your code (components, screens, etc.) as much as possible following our [Guiding Principles](https://testing-library.com/docs/guiding-principles). Additionally, most predicates promote the usage of proper accessibility props, which add a semantic layer on top of an element tree composed primarily of [`View`](https://reactnative.dev/docs/view) elements. + +It is recommended to use query predicates in the following order of priority: + +### 1. By Role query {#by-role-query} + +The first and most versatile predicate is [`*ByRole`](api-queries#by-role), which starts with the semantic role of the element and can be further narrowed down with additional options. React Native has two role systems, the web/ARIA-compatible one based on [`role`](https://reactnative.dev/docs/accessibility#role) prop and the traditional one based on [`accessibilityRole`](https://reactnative.dev/docs/accessibility#accessibilityrole) prop, you can use either of these. + +In most cases, you need to set accessibility roles explicitly (or your component library can set some of them for you). These roles allow assistive technologies (like screen readers) and testing code to understand your view hierarchy better. + +Some frequently used roles include: + +- `alert` - important text to be presented to the user, e.g., error message +- `button` +- `checkbox` & `switch` - on/off controls +- `heading` (`header`) - header for content section, e.g., the title of navigation bar +- `img` (`image`) +- `link` +- `menu` & `menuitem` +- `progressbar` +- `radiogroup` & `radio` +- `searchbox` (`search`) +- `slider` (`adjustable`) +- `summary` +- `tablist` & `tab` +- `text` - static text that cannot change +- `toolbar` - container for action buttons + +#### Name option {#by-role-query-name-option} + +Frequently, you will want to add the [`name`](api-queries#by-role-options) option, which will match both the element's role and its accessible name (= element's accessibility label or text content). + +Here are a couple of examples: + +- start button: `getByRole("button", { name: "Start" })` +- silent mode switch: `getByRole("switch", { name: "Silent Mode" })` +- screen header: `getByRole("header", { name: "Settings" })` +- undo menu item: `getByRole("menuitem", { name: "Undo" })` +- error messages: `getByRole("alert", { name: /Not logged in/ })` + +### 2. Text input queries {#text-input-queries} + +Querying [`TextInput`](https://reactnative.dev/docs/textinput) elements presents a unique challenge as there is no separate role for `TextInput` elements. There is a `searchbox`/`search` role, which can be assigned to `TextInput`, but it should be only used in the context of search inputs, leaving other text inputs without a role to query with. + +Therefore, you can use the following queries to find relevant text inputs: + +1. [`*ByLabelText`](api-queries#by-label-text) - will match the accessibility label of the element. This query will match any host elements, including `TextInput` elements. +2. [`*ByPlaceholderText`](api-queries#by-placeholder-text) - will match the placeholder of `TextInput` element. This query will match only `TextInput` elements. +3. [`*ByDisplayValue`](api-queries#by-display-value) - will the current (or default) value of `TextInput` element. This query will match only `TextInput` elements. + +### 3. Other accessible queries {#other-accessible-queries} + +These queries reflect the apps' user experience, both visual and through assistive technologies (e.g. screen reader). + +These queries include: + +- [`*ByText`](api-queries#by-text) - will match the text content of the element. This query will match only `Text` elements. +- [`*ByLabelText`](api-queries#by-label-text) - will match the accessibility label of the element. +- [`*ByHintText`](api-queries#by-hint-text) - will match the accessibility hint of the element. + +### 4. Test ID query {#test-id-query} + +As a final predicate, you can use the `testID` prop to find relevant views. Using the [`*ByTestId`](api-queries#by-test-id) predicate offers the most flexibility, but at the same time, it does not represent the user experience, as users are not aware of test IDs. + +Note that using test IDs is a widespread technique in end-to-end testing due to various issues with querying views through other means **in its specific context**. Nevertheless, we still encourage you to use recommended RNTL queries as it will make your integration and component test more reliable and resilient. diff --git a/website/docs/Queries.md b/website/docs/Queries.md index f99a765cd..9128f5137 100644 --- a/website/docs/Queries.md +++ b/website/docs/Queries.md @@ -2,6 +2,7 @@ id: api-queries title: Queries --- + import TOCInline from '@theme/TOCInline'; @@ -11,27 +12,27 @@ import TOCInline from '@theme/TOCInline'; > `getBy*` queries are shown by default in the [query documentation](#queries) > below. -### `getBy*` queries +### `getBy*` queries {#get-by} `getBy*` queries return the first matching node for a query, and throw an error if no elements match or if more than one match is found. If you need to find more than one element, then use `getAllBy`. -### `getAllBy*` queries +### `getAllBy*` queries {#get-all-by} `getAllBy*` queries return an array of all matching nodes for a query, and throw an error if no elements match. -### `queryBy*` queries +### `queryBy*` queries {#query-by} `queryBy*` queries return the first matching node for a query, and return `null` if no elements match. This is useful for asserting an element that is not present. This throws if more than one match is found (use `queryAllBy` instead). -### `queryAllBy*` queries +### `queryAllBy*` queries {#query-all-by} `queryAllBy*` queries return an array of all matching nodes for a query, and return an empty array (`[]`) when no elements match. -### `findBy*` queries +### `findBy*` queries {#find-by} `findBy*` queries return a promise which resolves when a matching element is found. The promise is rejected if no elements match or if more than one match is found after a default timeout of 1000 ms. If you need to find more than one element, then use `findAllBy*`. -### `findAllBy*` queries +### `findAllBy*` queries {#find-all-by} `findAllBy*` queries return a promise which resolves to an array of matching elements. The promise is rejected if no elements match after a default timeout of 1000 ms. @@ -60,7 +61,7 @@ type ReactTestInstance = { }; ``` -### `ByRole` +### `ByRole` {#by-role} > getByRole, getAllByRole, queryByRole, queryAllByRole, findByRole, findAllByRole @@ -89,9 +90,11 @@ Returns a `ReactTestInstance` with matching `role` or `accessibilityRole` prop. :::info In order for `*ByRole` queries to match an element it needs to be considered an accessibility element: + 1. `Text`, `TextInput` and `Switch` host elements are these by default. 2. `View` host elements need an explicit [`accessible`](https://reactnative.dev/docs/accessibility#accessible) prop set to `true` 3. Some React Native composite components like `Pressable` & `TouchableOpacity` render host `View` element with `accessible` prop already set. + ::: ```jsx @@ -107,23 +110,41 @@ const element2 = screen.getByRole('button', { name: 'Hello' }); const element3 = screen.getByRole('button', { name: 'Hello', disabled: true }); ``` -#### Options {#byrole-options} +#### Options {#by-role-options} + +- `name`: Finds an element with given `role`/`accessibilityRole` and an accessible name (= accessability label or text content). + +- `disabled`: You can filter elements by their disabled state (coming either from `aria-disabled` prop or `accessbilityState.disabled` prop). The possible values are `true` or `false`. Querying `disabled: false` will also match elements with `disabled: undefined` (see the [wiki](https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State) for more details). + + - See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `disabled` state. + - This option can alternatively be expressed using the [`toBeEnabled()` / `toBeDisabled()`](jest-matchers#tobeenabled) Jest matchers. + +- `selected`: You can filter elements by their selected state (coming either from `aria-selected` prop or `accessbilityState.selected` prop). The possible values are `true` or `false`. Querying `selected: false` will also match elements with `selected: undefined` (see the [wiki](https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State) for more details). + + - See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `selected` state. + - This option can alternatively be expressed using the [`toBeSelected()`](jest-matchers#tobeselected) Jest matcher. + +* `checked`: You can filter elements by their checked state (coming either from `aria-checked` prop or `accessbilityState.checked` prop). The possible values are `true`, `false`, or `"mixed"`. -`name`: Finds an element with given `role`/`accessibilityRole` and an accessible name (equivalent to `byText` or `byLabelText` query). + - See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `checked` state. + - This option can alternatively be expressed using the [`toBeChecked()` / `toBePartiallyChecked()`](jest-matchers#tobechecked) Jest matchers. -`disabled`: You can filter elements by their disabled state (coming either from `aria-disabled` prop or `accessbilityState.disabled` prop). The possible values are `true` or `false`. Querying `disabled: false` will also match elements with `disabled: undefined` (see the [wiki](https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State) for more details). See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `disabled` state. +* `busy`: You can filter elements by their busy state (coming either from `aria-busy` prop or `accessbilityState.busy` prop). The possible values are `true` or `false`. Querying `busy: false` will also match elements with `busy: undefined` (see the [wiki](https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State) for more details). -`selected`: You can filter elements by their selected state (coming either from `aria-selected` prop or `accessbilityState.selected` prop). The possible values are `true` or `false`. Querying `selected: false` will also match elements with `selected: undefined` (see the [wiki](https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State) for more details). See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `selected` state. + - See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `busy` state. + - This option can alternatively be expressed using the [`toBeBusy()`](jest-matchers#tobebusy) Jest matcher. -`checked`: You can filter elements by their checked state (coming either from `aria-checked` prop or `accessbilityState.checked` prop). The possible values are `true`, `false`, or `"mixed"`. See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `checked` state. +* `expanded`: You can filter elements by their expanded state (coming either from `aria-expanded` prop or `accessbilityState.expanded` prop). The possible values are `true` or `false`. -`busy`: You can filter elements by their busy state (coming either from `aria-busy` prop or `accessbilityState.busy` prop). The possible values are `true` or `false`. Querying `busy: false` will also match elements with `busy: undefined` (see the [wiki](https://github.com/callstack/react-native-testing-library/wiki/Accessibility:-State) for more details). See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `busy` state. + - See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `expanded` state. + - This option can alternatively be expressed using the [`toBeExpanded()` / `toBeCollapsed()`](jest-matchers#tobeexpanded) Jest matchers. -`expanded`: You can filter elements by their expanded state (coming either from `aria-expanded` prop or `accessbilityState.expanded` prop). The possible values are `true` or `false`. See [React Native's accessibilityState](https://reactnative.dev/docs/accessibility#accessibilitystate) docs to learn more about the `expanded` state. +* `value`: Filter elements by their accessibility value, based on either `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext` or `accessibilityValue` props. Accessiblity value conceptually consists of numeric `min`, `max` and `now` entries, as well as string `text` entry. -`value`: Filter elements by their accessibility value, based on either `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext` or `accessibilityValue` props. Accessiblity value conceptually consists of numeric `min`, `max` and `now` entries, as well as string `text` entry. See React Native [accessibilityValue](https://reactnative.dev/docs/accessibility#accessibilityvalue) docs to learn more about the accessibility value concept. + - See React Native [accessibilityValue](https://reactnative.dev/docs/accessibility#accessibilityvalue) docs to learn more about the accessibility value concept. + - This option can alternatively be expressed using the [`toHaveAccessibilityValue()`](jest-matchers#tohaveaccessibilityvalue) Jest matcher. -### `ByText` +### `ByText` {#by-text} > getByText, getAllByText, queryByText, queryAllByText, findByText, findAllByText @@ -149,7 +170,7 @@ render(); const element = screen.getByText('banana'); ``` -### `ByPlaceholderText` +### `ByPlaceholderText` {#by-placeholder-text} > getByPlaceholderText, getAllByPlaceholderText, queryByPlaceholderText, queryAllByPlaceholderText, findByPlaceholderText, findAllByPlaceholderText @@ -173,7 +194,7 @@ render(); const element = screen.getByPlaceholderText('username'); ``` -### `ByDisplayValue` +### `ByDisplayValue` {#by-display-value} > getByDisplayValue, getAllByDisplayValue, queryByDisplayValue, queryAllByDisplayValue, findByDisplayValue, findAllByDisplayValue @@ -197,7 +218,7 @@ render(); const element = screen.getByDisplayValue('username'); ``` -### `ByTestId` +### `ByTestId` {#by-test-id} > getByTestId, getAllByTestId, queryByTestId, queryAllByTestId, findByTestId, findAllByTestId @@ -225,7 +246,7 @@ const element = screen.getByTestId('unique-id'); 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). ::: -### `ByLabelText` +### `ByLabelText` {#by-label-text} > getByLabelText, getAllByLabelText, queryByLabelText, queryAllByLabelText, findByLabelText, findAllByLabelText @@ -241,6 +262,7 @@ getByLabelText( ``` Returns a `ReactTestInstance` with matching label: + - either by matching [`aria-label`](https://reactnative.dev/docs/accessibility#aria-label)/[`accessibilityLabel`](https://reactnative.dev/docs/accessibility#accessibilitylabel) prop - or by matching text content of view referenced by [`aria-labelledby`](https://reactnative.dev/docs/accessibility#aria-labelledby-android)/[`accessibilityLabelledBy`](https://reactnative.dev/docs/accessibility#accessibilitylabelledby-android) prop @@ -251,7 +273,7 @@ render(); const element = screen.getByLabelText('my-label'); ``` -### `ByHintText`, `ByA11yHint`, `ByAccessibilityHint` +### `ByHintText`, `ByA11yHint`, `ByAccessibilityHint` {#by-hint-text} > getByA11yHint, getAllByA11yHint, queryByA11yHint, queryAllByA11yHint, findByA11yHint, findAllByA11yHint > getByAccessibilityHint, getAllByAccessibilityHint, queryByAccessibilityHint, queryAllByAccessibilityHint, findByAccessibilityHint, findAllByAccessibilityHint @@ -281,19 +303,19 @@ const element = screen.getByHintText('Plays a song'); Please consult [Apple guidelines on how `accessibilityHint` should be used](https://developer.apple.com/documentation/objectivec/nsobject/1615093-accessibilityhint). ::: - - -### `ByA11yState`, `ByAccessibilityState` (deprecated) +### `ByA11yState`, `ByAccessibilityState` (deprecated) {#by-accessibility-state} :::caution This query has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of following options: -* [`*ByRole`](#byrole) query with relevant state options: `disabled`, `selected`, `checked`, `expanded` and `busy` -* use built-in Jest matchers to check the state of element found using some other query: - * enabled state: [`toBeEnabled()` / `toBeDisabled()`](jest-matchers#tobeenabled) - * checked state: [`toBeChecked()` / `toBePartiallyChecked()`](jest-matchers#tobechecked) - * selected state: [`toBeSelected()`](jest-matchers#tobeselected) - * expanded state: [`toBeExpanded()` / `toBeCollapsed()`](jest-matchers#tobeexpanded) - * busy state: [`toBeBusy()`](jest-matchers#tobebusy) + +- [`*ByRole`](#by-role) query with relevant state options: `disabled`, `selected`, `checked`, `expanded` and `busy` +- use built-in Jest matchers to check the state of element found using some other query: + - enabled state: [`toBeEnabled()` / `toBeDisabled()`](jest-matchers#tobeenabled) + - checked state: [`toBeChecked()` / `toBePartiallyChecked()`](jest-matchers#tobechecked) + - selected state: [`toBeSelected()`](jest-matchers#tobeselected) + - expanded state: [`toBeExpanded()` / `toBeCollapsed()`](jest-matchers#tobeexpanded) + - busy state: [`toBeBusy()`](jest-matchers#tobebusy) + ::: > getByA11yState, getAllByA11yState, queryByA11yState, queryAllByA11yState, findByA11yState, findAllByA11yState @@ -314,7 +336,7 @@ getByA11yState( ): ReactTestInstance; ``` -Returns a `ReactTestInstance` with matching `accessibilityState` prop or ARIA state props: `aria-disabled`, `aria-selected`, `aria-checked`, `aria-busy`, and `aria-expanded`. +Returns a `ReactTestInstance` with matching `accessibilityState` prop or ARIA state props: `aria-disabled`, `aria-selected`, `aria-checked`, `aria-busy`, and `aria-expanded`. ```jsx import { render, screen } from '@testing-library/react-native'; @@ -351,13 +373,14 @@ but will not match elements with following props: The difference in handling default values is made to reflect observed accessibility behaviour on iOS and Android platforms. ::: -### `ByA11yValue`, `ByAccessibilityValue` (deprecated) +### `ByA11yValue`, `ByAccessibilityValue` (deprecated) {#by-accessibility-value} :::caution This query has been marked deprecated, as is typically too general to give meaningful results. Therefore, it's better to use one of following options: -* [`toHaveAccessibilityValue()`](jest-matchers#tohaveaccessibilityvalue) Jest matcher to check the state of element found using some other query -* [`*ByRole`](#byrole) query with `value` option -::: + +- [`toHaveAccessibilityValue()`](jest-matchers#tohaveaccessibilityvalue) Jest matcher to check the state of element found using some other query +- [`*ByRole`](#by-role) query with `value` option + ::: > getByA11yValue, getAllByA11yValue, queryByA11yValue, queryAllByA11yValue, findByA11yValue, findAllByA11yValue > getByAccessibilityValue, getAllByAccessibilityValue, queryByAccessibilityValue, queryAllByAccessibilityValue, findByAccessibilityValue, findAllByAccessibilityValue @@ -409,7 +432,9 @@ render(Hidden from accessibility); // Exclude hidden elements expect( - screen.queryByText('Hidden from accessibility', { includeHiddenElements: false }) + screen.queryByText('Hidden from accessibility', { + includeHiddenElements: false, + }) ).not.toBeOnTheScreen(); // Include hidden elements @@ -463,6 +488,7 @@ screen.getByText(/hello world/); ``` ### Options {#text-match-options} + #### Precision ```typescript diff --git a/website/sidebars.js b/website/sidebars.js index f8b1f51eb..f27a0740c 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -3,9 +3,9 @@ module.exports = { Introduction: ['getting-started', 'faq'], 'API Reference': ['api', 'api-queries', 'jest-matchers', 'user-event'], Guides: [ - 'troubleshooting', 'how-should-i-query', 'eslint-plugin-testing-library', + 'troubleshooting', ], Advanced: ['testing-env', 'understanding-act'], Migrations: [ diff --git a/website/yarn.lock b/website/yarn.lock index 212129084..d84975bca 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -3952,17 +3952,10 @@ __metadata: languageName: node linkType: hard -"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30001426": - version: 1.0.30001456 - resolution: "caniuse-lite@npm:1.0.30001456" - checksum: a40dbc996af9683eac5e4e74c1b713e6b4744a9a8780b0ee9d47a866fb8628565e5faaf3497064438f1e92a661a8f9570cc2ec722d7693339def7ea9f31dc84d - languageName: node - linkType: hard - -"caniuse-lite@npm:^1.0.30001449": - version: 1.0.30001466 - resolution: "caniuse-lite@npm:1.0.30001466" - checksum: ac92474409942988c882ad2ff819a0c76288e6984067246cc8b08d047c3dc31c31847927eba0174be115c0520da7b67ab68ce0092d8100610e541c51cd99fd58 +"caniuse-lite@npm:^1.0.0, caniuse-lite@npm:^1.0.30001426, caniuse-lite@npm:^1.0.30001449": + version: 1.0.30001563 + resolution: "caniuse-lite@npm:1.0.30001563" + checksum: a8b367d43e0307ec243d8df8515d563fa3de895e9698eec4539037aed400da81e0df737164da2a6b7104ab6e75b4ea63db0adebcaabe326f2792841980259256 languageName: node linkType: hard