Skip to content

Commit bf4e88d

Browse files
committed
.
1 parent 521b56a commit bf4e88d

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ This guide describes built-in Jest matchers. These matchers provide readable ass
44

55
## Setup
66

7-
There is no need to set up the built-in matchers; they are automatically available in your tests when you import anything from `@testing-library/react-native`, e.g., `render`.
7+
No setup needed. Matchers are available when you import from `@testing-library/react-native`.
88

9-
## Migration from legacy Jest Native matchers.
9+
## Migration from legacy Jest Native matchers
1010

11-
If you are already using legacy Jest Native matchers we have a [migration guide](/docs/migration/jest-matchers) for moving to the built-in matchers.
11+
If you use legacy Jest Native matchers, see the [migration guide](/docs/migration/jest-matchers).
1212

1313
## Checking element existence
1414

@@ -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-
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.
21+
Checks if an element is attached to the element tree. If a referenced element gets unmounted during the test, this assertion fails.
2222

2323
## Element Content
2424

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

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`.
37+
Checks if the element has the specified text content. Accepts `string` or `RegExp`, with optional [text match options](/docs/api/queries#text-match-options) `exact` and `normalizer`.
3838

3939
### `toContainElement()`
4040

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

47-
Checks if the container element contains another host element.
47+
Checks if a container element contains another element.
4848

4949
### `toBeEmptyElement()`
5050

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

55-
Checks if the element has no host child elements or text content.
55+
Checks if the element has no child elements or text content.
5656

5757
## Checking element state
5858

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

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`.
71+
Checks if a `TextInput` has the specified display value. Accepts `string` or `RegExp`, with optional [text match options](/docs/api/queries#text-match-options) `exact` and `normalizer`.
7272

7373
### `toHaveAccessibilityValue()`
7474

@@ -85,9 +85,9 @@ expect(element).toHaveAccessibilityValue(
8585

8686
Checks if the element has a specified accessible value.
8787

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.
88+
Reads from `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext`, and `accessibilityValue` props. Only the values you specify are checked, so the element can have other accessibility value entries and still match.
8989

90-
When querying by `text` entry a string or `RegExp` might be used.
90+
For the `text` entry, you can use `string` or `RegExp`.
9191

9292
### `toBeEnabled()` / `toBeDisabled` {#tobeenabled}
9393

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

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.
99+
Checks if the element is enabled or disabled based on `aria-disabled` or `accessibilityState.disabled` props. An element is disabled when it or any ancestor is disabled.
100100

101101
:::note
102-
These matchers are the negation of each other, and both are provided to avoid double negations in your assertions.
102+
These matchers are opposites. Both are provided to avoid double negations in assertions.
103103
:::
104104

105105
### `toBeSelected()`
@@ -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-
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.
111+
Checks if the element is selected based on `aria-selected` or `accessibilityState.selected` props.
112112

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

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

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.
120+
Checks if the element is checked or partially checked based on `aria-checked` or `accessibilityState.checked` props.
121121

122122
:::note
123123

124-
- `toBeChecked()` matcher works only on `Switch` host elements and accessibility elements with `checkbox`, `radio` or `switch` role.
125-
- `toBePartiallyChecked()` matcher works only on elements with `checkbox` role.
124+
- `toBeChecked()` works only on `Switch` elements and elements with `checkbox`, `radio`, or `switch` role.
125+
- `toBePartiallyChecked()` works only on elements with `checkbox` role.
126126

127127
:::
128128

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

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.
136+
Checks if the element is expanded or collapsed based on `aria-expanded` or `accessibilityState.expanded` props.
137137

138138
:::note
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).
139+
These matchers are opposites for expandable elements (those with explicit `aria-expanded` or `accessibilityState.expanded` props). For non-expandable elements, neither matcher passes.
140140
:::
141141

142142
### `toBeBusy()`
@@ -145,7 +145,7 @@ These matchers are the negation of each other for expandable elements (elements
145145
expect(element).toBeBusy();
146146
```
147147

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.
148+
Checks if the element is busy based on `aria-busy` or `accessibilityState.busy` props.
149149

150150
## Checking element style
151151

@@ -155,9 +155,9 @@ Checks if the element is busy from the user's perspective. Relies on the accessi
155155
expect(element).toBeVisible();
156156
```
157157

158-
Checks if the element is visible from the user's perspective.
158+
Checks if the element is visible.
159159

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.
160+
An element is invisible when it or any ancestor has `display: none` or `opacity: 0` styles, or when it's hidden from accessibility.
161161

162162
### `toHaveStyle()`
163163

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

170-
Checks if the element has the specified styles.
170+
Checks if the element has specific styles.
171171

172172
## Other matchers
173173

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

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`.
186+
Checks if the element has the specified accessible name. Accepts `string` or `RegExp`, with optional [text match options](/docs/api/queries#text-match-options) `exact` and `normalizer`.
187187

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.
188+
The accessible name comes from `aria-labelledby`, `accessibilityLabelledBy`, `aria-label`, and `accessibilityLabel` props. If none are present, the element's text content is used.
189189

190-
When the `name` parameter is `undefined` it will only check if the element has any accessible name.
190+
Without a `name` parameter (or with `undefined`), it only checks if the element has any accessible name.
191191

192192
### `toHaveProp()`
193193

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

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.
201+
Checks if the element has a prop. Without a `value` (or with `undefined`), it only checks if the prop exists. With a `value`, it checks if the prop's value matches.
202202

203203
:::note
204-
This matcher should be treated as an escape hatch to be used when all other matchers are not suitable.
204+
Use this matcher as a last resort when other matchers don't fit your needs.
205205
:::

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide covers the built-in Jest matchers. These matchers make your tests eas
44

55
## Setup
66

7-
There is no need to set up the built-in matchers; they are automatically available in your tests when you import anything from `@testing-library/react-native`, e.g., `render`.
7+
No setup needed. Matchers are available when you import from `@testing-library/react-native`.
88

99
## Checking element existence
1010

@@ -30,7 +30,7 @@ expect(element).toHaveTextContent(
3030
)
3131
```
3232

33-
Checks if an element has the specified text content. You can pass a `string` or `RegExp`, plus [text match options](/docs/api/queries#text-match-options) like `exact` and `normalizer`.
33+
Checks if an element has the specified text content. Accepts `string` or `RegExp`, with optional [text match options](/docs/api/queries#text-match-options) like `exact` and `normalizer`.
3434

3535
### `toContainElement()`
3636

@@ -40,15 +40,15 @@ expect(container).toContainElement(
4040
)
4141
```
4242

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

4545
### `toBeEmptyElement()`
4646

4747
```ts
4848
expect(element).toBeEmptyElement();
4949
```
5050

51-
Checks if an element has no host child elements or text content.
51+
Checks if an element has no child elements or text content.
5252

5353
## Checking element state
5454

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

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`.
67+
Checks if a `TextInput` has the specified display value. Accepts `string` or `RegExp`, with optional [text match options](/docs/api/queries#text-match-options) like `exact` and `normalizer`.
6868

6969
### `toHaveAccessibilityValue()`
7070

@@ -81,7 +81,7 @@ expect(element).toHaveAccessibilityValue(
8181

8282
Checks if an element has the specified accessible value.
8383

84-
The matcher checks accessibility values from `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext`, and `accessibilityValue` props. It only checks the values you specifythe element can have other accessibility value entries and still match.
84+
The matcher reads accessibility values from `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, `aria-valuetext`, and `accessibilityValue` props. It only checks the values you specify, so the element can have other accessibility value entries and still match.
8585

8686
For the `text` entry, you can use a string or `RegExp`.
8787

@@ -92,7 +92,7 @@ expect(element).toBeEnabled();
9292
expect(element).toBeDisabled();
9393
```
9494

95-
Checks if an element is enabled or disabled. Uses the accessibility disabled state from `aria-disabled` or `accessibilityState.disabled` props. An element is considered disabled if it or any of its ancestors is disabled.
95+
Checks if an element is enabled or disabled from `aria-disabled` or `accessibilityState.disabled` props. An element is disabled if it or any ancestor is disabled.
9696

9797
:::note
9898
These matchers are opposites. Both are available so you can avoid double negations like `expect(element).not.toBeDisabled()`.
@@ -104,7 +104,7 @@ These matchers are opposites. Both are available so you can avoid double negatio
104104
expect(element).toBeSelected();
105105
```
106106

107-
Checks if an element is selected. Uses the accessibility selected state from `aria-selected` or `accessibilityState.selected` props.
107+
Checks if an element is selected from `aria-selected` or `accessibilityState.selected` props.
108108

109109
### `toBeChecked()` / `toBePartiallyChecked()` {#tobechecked}
110110

@@ -113,7 +113,7 @@ expect(element).toBeChecked();
113113
expect(element).toBePartiallyChecked();
114114
```
115115

116-
Checks if an element is checked or partially checked. Uses the accessibility checked state from `aria-checked` or `accessibilityState.checked` props.
116+
Checks if an element is checked or partially checked from `aria-checked` or `accessibilityState.checked` props.
117117

118118
:::note
119119

@@ -129,7 +129,7 @@ expect(element).toBeExpanded();
129129
expect(element).toBeCollapsed();
130130
```
131131

132-
Checks if an element is expanded or collapsed. Uses the accessibility expanded state from `aria-expanded` or `accessibilityState.expanded` props.
132+
Checks if an element is expanded or collapsed from `aria-expanded` or `accessibilityState.expanded` props.
133133

134134
:::note
135135
These matchers are opposites for expandable elements (those with explicit `aria-expanded` or `accessibilityState.expanded` props). For non-expandable elements, neither matcher will pass.
@@ -141,7 +141,7 @@ These matchers are opposites for expandable elements (those with explicit `aria-
141141
expect(element).toBeBusy();
142142
```
143143

144-
Checks if an element is busy. Uses the accessibility busy state from `aria-busy` or `accessibilityState.busy` props.
144+
Checks if an element is busy from `aria-busy` or `accessibilityState.busy` props.
145145

146146
## Checking element style
147147

@@ -153,7 +153,7 @@ expect(element).toBeVisible();
153153

154154
Checks if an element is visible.
155155

156-
An element is considered invisible if it or any of its ancestors has `display: none` or `opacity: 0` styles, or if it's hidden from accessibility.
156+
An element is invisible if it or any ancestor has `display: none` or `opacity: 0` styles, or if it's hidden from accessibility.
157157

158158
### `toHaveStyle()`
159159

@@ -163,7 +163,7 @@ expect(element).toHaveStyle(
163163
)
164164
```
165165

166-
Checks if an element has the specified styles.
166+
Checks if an element has specific styles.
167167

168168
## Other matchers
169169

@@ -179,11 +179,11 @@ expect(element).toHaveAccessibleName(
179179
)
180180
```
181181

182-
Checks if an element has the specified accessible name. You can pass a `string` or `RegExp`, plus [text match options](/docs/api/queries#text-match-options) like `exact` and `normalizer`.
182+
Checks if an element has the specified accessible name. Accepts `string` or `RegExp`, with optional [text match options](/docs/api/queries#text-match-options) like `exact` and `normalizer`.
183183

184-
The accessible name comes from `aria-labelledby`, `accessibilityLabelledBy`, `aria-label`, and `accessibilityLabel` props. For `Image` elements, the `alt` prop is also used. If none of these are present, the element's text content is used.
184+
The accessible name comes from `aria-labelledby`, `accessibilityLabelledBy`, `aria-label`, and `accessibilityLabel` props. For `Image` elements, the `alt` prop is also used. If none are present, the element's text content is used.
185185

186-
If you don't pass a `name` parameter (or pass `undefined`), it only checks whether the element has any accessible name.
186+
Without a `name` parameter (or with `undefined`), it only checks whether the element has any accessible name.
187187

188188
### `toHaveProp()`
189189

@@ -194,7 +194,7 @@ expect(element).toHaveProp(
194194
)
195195
```
196196

197-
Checks if an element has a prop. If you don't pass a `value` (or pass `undefined`), it only checks if the prop exists. If you pass a `value`, it checks if the prop's value matches.
197+
Checks if an element has a prop. Without a `value` (or with `undefined`), it only checks if the prop exists. With a `value`, it checks if the prop's value matches.
198198

199199
:::note
200200
Use this matcher as a last resort when other matchers don't fit your needs.

0 commit comments

Comments
 (0)