You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/13.x/docs/api/jest-matchers.mdx
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Jest matchers
2
2
3
-
This guide describes built-in Jest matchers. We recommend using these matchers as they provide readable tests, accessibility support, and a better developer experience.
3
+
This guide describes built-in Jest matchers. These matchers provide readable assertions with accessibility support.
4
4
5
5
## Setup
6
6
@@ -18,7 +18,7 @@ If you are already using legacy Jest Native matchers we have a [migration guide]
18
18
expect(element).toBeOnTheScreen();
19
19
```
20
20
21
-
This allows you to assert whether an element is attached to the element tree or not. If you hold a reference to an element and it gets unmounted during the test it will no longer pass this assertion.
21
+
Checks if an element is attached to the element tree. If you hold a reference to an element and it gets unmounted during the test, it will no longer pass this assertion.
This allows you to assert whether the given element has the given text content or not. It accepts either`string` or `RegExp` matchers, as well as [text match options](/docs/api/queries#text-match-options) of `exact` and `normalizer`.
37
+
Checks if the element has the specified text content. Accepts`string` or `RegExp` matchers, as well as [text match options](/docs/api/queries#text-match-options) of `exact` and `normalizer`.
This allows you to assert whether the given `TextInput` element has a specified display value. It accepts either`string` or `RegExp` matchers, as well as [text match options](/docs/api/queries#text-match-options) of `exact` and `normalizer`.
71
+
Checks if the `TextInput` element has the specified display value. Accepts`string` or `RegExp` matchers, as well as [text match options](/docs/api/queries#text-match-options) of `exact` and `normalizer`.
This allows you to assert whether the given element has a specified accessible value.
86
+
Checks if the element has a specified accessible value.
87
87
88
88
This matcher will assert accessibility value based on `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext` and `accessibilityValue` props. Only defined value entries will be used in the assertion, the element might have additional accessibility value entries and still be matched.
89
89
@@ -96,7 +96,7 @@ expect(element).toBeEnabled();
96
96
expect(element).toBeDisabled();
97
97
```
98
98
99
-
These allow you to assert whether the given element is enabled or disabled from the user's perspective. It relies on the accessibility disabled state as set by `aria-disabled` or `accessibilityState.disabled` props. It will consider a given element disabled when it or any of its ancestors is disabled.
99
+
Checks if the element is enabled or disabled from the user's perspective. These rely on the accessibility disabled state set by `aria-disabled` or `accessibilityState.disabled` props. An element is considered disabled when it or any of its ancestors is disabled.
100
100
101
101
:::note
102
102
These matchers are the negation of each other, and both are provided to avoid double negations in your assertions.
@@ -108,7 +108,7 @@ These matchers are the negation of each other, and both are provided to avoid do
108
108
expect(element).toBeSelected();
109
109
```
110
110
111
-
This allows you to assert whether the given element is selected from the user's perspective. It relies on the accessibility selected state as set by `aria-selected` or `accessibilityState.selected` props.
111
+
Checks if the element is selected from the user's perspective. Relies on the accessibility selected state set by `aria-selected` or `accessibilityState.selected` props.
These allow you to assert whether the given element is checked or partially checked from the user's perspective. It relies on the accessibility checked state as set by `aria-checked` or `accessibilityState.checked` props.
120
+
Checks if the element is checked or partially checked from the user's perspective. These rely on the accessibility checked state set by `aria-checked` or `accessibilityState.checked` props.
These allow you to assert whether the given element is expanded or collapsed from the user's perspective. They rely on the accessibility expanded state as set by `aria-expanded` or `accessibilityState.expanded` props.
136
+
Checks if the element is expanded or collapsed from the user's perspective. These rely on the accessibility expanded state set by `aria-expanded` or `accessibilityState.expanded` props.
137
137
138
138
:::note
139
139
These matchers are the negation of each other for expandable elements (elements with explicit `aria-expanded` or `accessibilityState.expanded` props). However, both won't pass for non-expandable elements (ones without explicit `aria-expanded` or `accessibilityState.expanded` props).
@@ -145,7 +145,7 @@ These matchers are the negation of each other for expandable elements (elements
145
145
expect(element).toBeBusy();
146
146
```
147
147
148
-
This allows you to assert whether the given element is busy from the user's perspective. It relies on the accessibility busy state as set by `aria-busy` or `accessibilityState.busy` props.
148
+
Checks if the element is busy from the user's perspective. Relies on the accessibility busy state set by `aria-busy` or `accessibilityState.busy` props.
149
149
150
150
## Checking element style
151
151
@@ -155,7 +155,7 @@ This allows you to assert whether the given element is busy from the user's pers
155
155
expect(element).toBeVisible();
156
156
```
157
157
158
-
This allows you to assert whether the given element is visible from the user's perspective.
158
+
Checks if the element is visible from the user's perspective.
159
159
160
160
The element is considered invisible when itself or any of its ancestors has `display: none` or `opacity: 0` styles, as well as when it's hidden from accessibility.
161
161
@@ -167,7 +167,7 @@ expect(element).toHaveStyle(
167
167
)
168
168
```
169
169
170
-
This allows you to assert whether the given element has given styles.
This allows you to assert whether the given element has a specified accessible name. It accepts either`string` or `RegExp` matchers, as well as [text match options](/docs/api/queries#text-match-options) of `exact` and `normalizer`.
186
+
Checks if the element has the specified accessible name. Accepts`string` or `RegExp` matchers, as well as [text match options](/docs/api/queries#text-match-options) of `exact` and `normalizer`.
187
187
188
188
The accessible name will be computed based on `aria-labelledby`, `accessibilityLabelledBy`, `aria-label`, and `accessibilityLabel` props, in the absence of these props, the element text content will be used.
189
189
@@ -198,7 +198,7 @@ expect(element).toHaveProp(
198
198
)
199
199
```
200
200
201
-
This allows you to assert whether the given element has a given prop. When the `value`parameter is `undefined` it will only check for existence of the prop, and when `value` is defined it will check if the actual value matches passed value.
201
+
Checks if the element has the specified prop. When `value` is `undefined`, it only checks for existence of the prop. When `value` is defined, it checks if the actual value matches.
202
202
203
203
:::note
204
204
This matcher should be treated as an escape hatch to be used when all other matchers are not suitable.
Copy file name to clipboardExpand all lines: website/docs/13.x/docs/api/queries.mdx
+12-15Lines changed: 12 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Queries
2
2
3
-
Queries are one of the main building blocks for the React Native Testing Library. They enable you to find relevant elements in the element tree, which represents your application's user interface when running under tests.
3
+
Queries are one of the main building blocks of React Native Testing Library. They let you find elements in the element tree, which represents your application's user interface when running under tests.
The modern and recommended way to access queries is to use the `screen` object exported by the `@testing-library/react-native` package. This object contains methods for all available queries bound to the most recently rendered UI.
21
+
The recommended way to access queries is to use the `screen` object exported by `@testing-library/react-native`. It contains methods for all available queries bound to the most recently rendered UI.
22
22
23
23
### Using `render` result
24
24
@@ -35,19 +35,16 @@ The classic way is to capture query functions returned from the `render` functio
35
35
36
36
## Query parts
37
37
38
-
Each query is composed of two parts: variant and predicate, which are separated by the `by`word in the middle of the name.
38
+
Each query is composed of two parts: variant and predicate, separated by the word `by` in the middle.
39
39
40
-
Consider the following query:
40
+
Consider the query`getByRole()`:
41
41
42
-
```
43
-
getByRole()
44
-
```
45
-
46
-
For this query, `getBy*` is the query variant, and `*ByRole` is the predicate.
42
+
-`getBy*` is the query variant
43
+
-`*ByRole` is the predicate
47
44
48
45
## Query variant
49
46
50
-
The query variants describe the expected number (and timing) of matching elements, so they differ in their return type.
47
+
The query variants describe the expected number (and timing) of matching elements, so they differ in return type.
@@ -130,7 +127,7 @@ When your `findBy*` and `findAllBy*` queries throw because they can't find match
130
127
131
128
## Query predicates
132
129
133
-
_Note: most methods like this one return a [`ReactTestInstance`](https://reactjs.org/docs/test-renderer.html#testinstance) with following properties that you may be interested in:_
130
+
_Note: most methods like this one return a [`ReactTestInstance`](https://reactjs.org/docs/test-renderer.html#testinstance) with the following properties that you may be interested in:_
134
131
135
132
```typescript
136
133
typeReactTestInstance= {
@@ -169,7 +166,7 @@ getByRole(
169
166
Returns a `ReactTestInstance` with matching `role` or `accessibilityRole` prop.
170
167
171
168
:::info
172
-
In order for `*ByRole` queries to match an element it needs to be considered an accessibility element:
169
+
For `*ByRole` queries to match an element, it needs to be considered an accessibility element:
173
170
174
171
1.`Text`, `TextInput` and `Switch` host elements are these by default.
175
172
2.`View` host elements need an explicit [`accessible`](https://reactnative.dev/docs/accessibility#accessible) prop set to `true`
@@ -236,7 +233,7 @@ getByLabelText(
236
233
Returns a `ReactTestInstance` with matching label:
237
234
238
235
- either by matching [`aria-label`](https://reactnative.dev/docs/accessibility#aria-label)/[`accessibilityLabel`](https://reactnative.dev/docs/accessibility#accessibilitylabel) prop
239
-
- 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
236
+
- or by matching the text content of the view referenced by [`aria-labelledby`](https://reactnative.dev/docs/accessibility#aria-labelledby-android)/[`accessibilityLabelledBy`](https://reactnative.dev/docs/accessibility#accessibilitylabelledby-android) prop
Returns a `ReactTestInstance` with matching text—may be a string or regular expression.
308
+
Returns a `ReactTestInstance` with matching text. The text can be a string or regular expression.
312
309
313
310
This method joins `<Text>` siblings to find matches, similarly to [how React Native handles these components](https://reactnative.dev/docs/text#containers). This allows querying for strings that will be visually rendered together but may be semantically separate React components.
Checks if a`TextInput` element has the specified display value. You can pass a `string` or `RegExp`, plus [text match options](/docs/api/queries#text-match-options) like `exact` and `normalizer`.
67
+
Checks if the`TextInput` element has the specified display value. You can pass a `string` or `RegExp`, plus [text match options](/docs/api/queries#text-match-options) like `exact` and `normalizer`.
0 commit comments