Skip to content

Commit 01d5050

Browse files
committed
docs: cross references
1 parent 2f4741d commit 01d5050

File tree

2 files changed

+83
-3
lines changed

2 files changed

+83
-3
lines changed

website/docs/JestMatchers.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ id: jest-matchers
33
title: Jest Matchers
44
---
55

6+
This guide describes built-in Jest matchers, we recommend using these matchers as they provide more readable tests, better accessibility support and better developer experience.
7+
8+
If you are already using legacy Jest Native matchers we have a [migration guide](MigrationJestMatchers.md) for moving to the built-in matchers.
9+
610
import TOCInline from '@theme/TOCInline';
711

812
<TOCInline toc={toc} />
@@ -93,7 +97,7 @@ This matcher will assert accessibility value based on `aria-valuemin`, `aria-val
9397
When querying by `text` entry a string or `RegExp` might be used.
9498

9599

96-
### `toBeEnabled()` / `toBeDisabled`
100+
### `toBeEnabled()` / `toBeDisabled` {#tobeenabled}
97101

98102
```ts
99103
expect(element).toBeEnabled()
@@ -116,7 +120,7 @@ expect(element).toBeSelected()
116120
This allows you to assert whether the given element is selected from user's perspective. It relies on accessibility selected state as set by `aria-selected` or `accessibilityState.selected` props.
117121

118122

119-
### `toBeChecked()` / `toBePartiallyChecked()`
123+
### `toBeChecked()` / `toBePartiallyChecked()` {#tobechecked}
120124

121125
```ts
122126
expect(element).toBeChecked()
@@ -130,7 +134,7 @@ These allows you to assert whether the given element is checked or partially che
130134
* `toBePartiallyChecked()` matchers works only on elements with `checkbox` role.
131135
:::
132136

133-
### `toBeExpanded()` / `toBeCollapsed()`
137+
### `toBeExpanded()` / `toBeCollapsed()` {#tobeexpanded}
134138

135139
```ts
136140
expect(element).toBeExpanded()

website/docs/MigrationJestMatchers.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
id: migration-jest-native
3+
title: Migration from Jest Native matchers
4+
---
5+
6+
This guide describes steps necessary to migrate from [legacy Jest Native matchers](https://github.com/testing-library/jest-native) `v5` to [built-in Jest matchers](JestMatchers.md).
7+
8+
import TOCInline from '@theme/TOCInline';
9+
10+
<TOCInline toc={toc} />
11+
12+
## General notes
13+
14+
All of built-in Jest matchers provided by React Native Testing Library are supporting only host elements. This should not be an issue, as all RNTL v12 queries already return only host elements. When this guide states that given matcher should work the same it assumes behavior only only host elements. If you need to assert status of composite elements use Jest Native matchers in [legacy mode](#gradual-migration).
15+
16+
## Usage
17+
18+
You can use the built-in matchers by adding following line to your `jest-setup.ts` file:
19+
20+
```ts
21+
import '@testing-library/react-native/extend-expect';
22+
```
23+
24+
### Gradual migration
25+
26+
You can use the built-in matchers alongside with legacy Jest Native matchers by chaning their import in your `jest-setup.ts` file:
27+
28+
```ts
29+
// Replace this:
30+
// import '@testing-library/jest-native/extend-expect';
31+
32+
// With this:
33+
import '@testing-library/react-native/extend-expect';
34+
import '@testing-library/jest-native/legacy-extend-expect';
35+
```
36+
37+
In such case legacy matchers will be available using `legacy_` prefix, e.g.:
38+
39+
```ts
40+
expect(element).legacy_toHaveAccessibilityState({ busy: true });
41+
```
42+
43+
## Migration details
44+
45+
### Matchers not requiring changes
46+
47+
Following matchers should work the same:
48+
* [`toBeEmptyElement()`](JestMatchers.md#tobeemptyelement)
49+
* [`toBeEnabled()` / `toBeDisabled()`](JestMatchers.md#tobeenabled)
50+
* [`toBeOnTheScreen()`](JestMatchers.md#tobeonthescreen)
51+
* [`toBeVisible()`](JestMatchers.md#tobevisible)
52+
* [`toContainElement()`](JestMatchers.md#tocontainelement)
53+
* [`toHaveDisplayValue()`](JestMatchers.md#tohavedisplayvalue)
54+
* [`toHaveProp()`](JestMatchers.md#tohaveprop)
55+
* [`toHaveStyle()`](JestMatchers.md#tohavestyle)
56+
* [`toHaveTextContent()`](JestMatchers.md#tohavetextcontent)
57+
58+
### Renamed matchers
59+
60+
`toHaveAccessibilityValue()` matcher has been renamed to [`toHaveAccessibleValue()`](JestMatchers.md#tohaveaccessiblevalue) but otherwise should work the same.
61+
62+
### Removed matchers
63+
64+
`toHaveAccessibilityState()` matcher has been replaced by following matchers:
65+
* enabled state: [`toBeEnabled()` / `toBeDisabled()`](JestMatchers.md#tobeenabled)
66+
* checked state: [`toBeChecked()` / `toBePartiallyChecked()`](JestMatchers.md#tobechecked)
67+
* selected state: [`toBeSelected()`](JestMatchers.md#tobeselected)
68+
* expanded state: [`toBeExpanded()` / `toBeCollapsed()`](JestMatchers.md#tobeexpanded)
69+
* busy state: [`toBeBusy()`](JestMatchers.md#tobebusy)
70+
71+
The new matchers support both `accessbililityState` and `aria-*` props.
72+
73+
You should be aware of following changes:
74+
* [`toBeEnabled()` / `toBeDisabled()`](JestMatchers.md#tobeenabled) matchers also check the disabled state for element ancestors and not only the element itself
75+
* [`toBeChecked()`](JestMatchers.md#tobechecked) matcher supports only elements with `checkbox` or `radio` role
76+
* [`toBePartiallyChecked()`](JestMatchers.md#tobechecked) matchers supports only elements with `checkbox` role

0 commit comments

Comments
 (0)