Skip to content

Commit 518b016

Browse files
committed
tweaks
1 parent ab2b2c5 commit 518b016

File tree

4 files changed

+32
-35
lines changed

4 files changed

+32
-35
lines changed

website/docs/13.x/docs/api/jest-matchers.mdx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Jest matchers
22

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.
44

55
## Setup
66

@@ -18,7 +18,7 @@ If you are already using legacy Jest Native matchers we have a [migration guide]
1818
expect(element).toBeOnTheScreen();
1919
```
2020

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.
2222

2323
## Element Content
2424

@@ -34,7 +34,7 @@ expect(element).toHaveTextContent(
3434
)
3535
```
3636

37-
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`.
3838

3939
### `toContainElement()`
4040

@@ -44,15 +44,15 @@ expect(container).toContainElement(
4444
)
4545
```
4646

47-
This allows you to assert whether the given container element does contain another host element.
47+
Checks if the container element contains another host element.
4848

4949
### `toBeEmptyElement()`
5050

5151
```ts
5252
expect(element).toBeEmptyElement();
5353
```
5454

55-
This allows you to assert whether the given element does not have any host child elements or text content.
55+
Checks if the element has no host child elements or text content.
5656

5757
## Checking element state
5858

@@ -68,7 +68,7 @@ expect(element).toHaveDisplayValue(
6868
)
6969
```
7070

71-
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`.
7272

7373
### `toHaveAccessibilityValue()`
7474

@@ -83,7 +83,7 @@ expect(element).toHaveAccessibilityValue(
8383
)
8484
```
8585

86-
This allows you to assert whether the given element has a specified accessible value.
86+
Checks if the element has a specified accessible value.
8787

8888
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.
8989

@@ -96,7 +96,7 @@ expect(element).toBeEnabled();
9696
expect(element).toBeDisabled();
9797
```
9898

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.
100100

101101
:::note
102102
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
108108
expect(element).toBeSelected();
109109
```
110110

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.
112112

113113
### `toBeChecked()` / `toBePartiallyChecked()` {#tobechecked}
114114

@@ -117,7 +117,7 @@ expect(element).toBeChecked();
117117
expect(element).toBePartiallyChecked();
118118
```
119119

120-
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.
121121

122122
:::note
123123

@@ -133,7 +133,7 @@ expect(element).toBeExpanded();
133133
expect(element).toBeCollapsed();
134134
```
135135

136-
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.
137137

138138
:::note
139139
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
145145
expect(element).toBeBusy();
146146
```
147147

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.
149149

150150
## Checking element style
151151

@@ -155,7 +155,7 @@ This allows you to assert whether the given element is busy from the user's pers
155155
expect(element).toBeVisible();
156156
```
157157

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.
159159

160160
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.
161161

@@ -167,7 +167,7 @@ expect(element).toHaveStyle(
167167
)
168168
```
169169

170-
This allows you to assert whether the given element has given styles.
170+
Checks if the element has the specified styles.
171171

172172
## Other matchers
173173

@@ -183,7 +183,7 @@ expect(element).toHaveAccessibleName(
183183
)
184184
```
185185

186-
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`.
187187

188188
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.
189189

@@ -198,7 +198,7 @@ expect(element).toHaveProp(
198198
)
199199
```
200200

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.
202202

203203
:::note
204204
This matcher should be treated as an escape hatch to be used when all other matchers are not suitable.

website/docs/13.x/docs/api/queries.mdx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Queries
22

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.
44

55
## Accessing queries
66

@@ -18,7 +18,7 @@ test('accessing queries using "screen" object', () => {
1818
})
1919
```
2020

21-
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.
2222

2323
### Using `render` result
2424

@@ -35,19 +35,16 @@ The classic way is to capture query functions returned from the `render` functio
3535

3636
## Query parts
3737

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.
3939

40-
Consider the following query:
40+
Consider the query `getByRole()`:
4141

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
4744

4845
## Query variant
4946

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.
5148

5249
| Variant | Assertion | Return type | Is Async? |
5350
| ----------------------------------------------- | ----------------------------- | ------------------------------------------ | --------- |
@@ -130,7 +127,7 @@ When your `findBy*` and `findAllBy*` queries throw because they can't find match
130127

131128
## Query predicates
132129

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:_
134131

135132
```typescript
136133
type ReactTestInstance = {
@@ -169,7 +166,7 @@ getByRole(
169166
Returns a `ReactTestInstance` with matching `role` or `accessibilityRole` prop.
170167

171168
:::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:
173170

174171
1. `Text`, `TextInput` and `Switch` host elements are these by default.
175172
2. `View` host elements need an explicit [`accessible`](https://reactnative.dev/docs/accessibility#accessible) prop set to `true`
@@ -236,7 +233,7 @@ getByLabelText(
236233
Returns a `ReactTestInstance` with matching label:
237234

238235
- 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
240237

241238
```jsx
242239
import { render, screen } from '@testing-library/react-native';
@@ -284,7 +281,7 @@ getByDisplayValue(
284281
): ReactTestInstance;
285282
```
286283

287-
Returns a `ReactTestInstance` for a `TextInput` with a matching display value—may be a string or regular expression.
284+
Returns a `ReactTestInstance` for a `TextInput` with a matching display value. The value can be a string or regular expression.
288285

289286
```jsx
290287
import { render, screen } from '@testing-library/react-native';
@@ -308,7 +305,7 @@ getByText(
308305
): ReactTestInstance;
309306
```
310307

311-
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.
312309

313310
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.
314311

website/docs/14.x/docs/api/jest-matchers.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ expect(container).toContainElement(
4040
)
4141
```
4242

43-
Checks if a container element contains another host element.
43+
Checks if the container element contains another host element.
4444

4545
### `toBeEmptyElement()`
4646

@@ -64,7 +64,7 @@ expect(element).toHaveDisplayValue(
6464
)
6565
```
6666

67-
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`.
6868

6969
### `toHaveAccessibilityValue()`
7070

website/docs/14.x/docs/api/queries.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ Returns a `HostElement` with matching `role` or `accessibilityRole` prop.
171171
:::info
172172
In order for `*ByRole` queries to match an element it needs to be considered an accessibility element:
173173

174-
1. `Text`, `TextInput` and `Switch` host elements are these by default.
175-
2. `View` host elements need an explicit [`accessible`](https://reactnative.dev/docs/accessibility#accessible) prop set to `true`
174+
1. `Text`, `TextInput` and `Switch` elements are these by default.
175+
2. `View` elements need an explicit [`accessible`](https://reactnative.dev/docs/accessibility#accessible) prop set to `true`
176176
3. Some React Native composite components like `Pressable` & `TouchableOpacity` render host `View` element with `accessible` prop already set.
177177

178178
:::

0 commit comments

Comments
 (0)