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
@@ -28,20 +49,83 @@ Open a Terminal in your project's folder and run:
28
49
yarn add --dev react-testing-library
29
50
```
30
51
31
-
This library has a peerDependencies listing for `react-test-renderer` and, of course, `react`.
52
+
This library has a peerDependencies listing for `react-test-renderer` and, of course, `react`. Make sure to install them too!
53
+
54
+
As you may have noticed, it's not tied to React Native at all – you can safely use it in your React components if you feel like not interacting directly with DOM.
32
55
33
56
## Usage
34
57
35
58
## `render`
36
59
37
-
Deeply render given React component and returns helpers to query the output. For convenience it also returns `react-test-renderer`'s `instance` and `renderer` objects, in case you need more control.
60
+
Defined as:
61
+
62
+
```jsx
63
+
functionrender(
64
+
component:React.Element<*>,
65
+
options?: {
66
+
/* You won't often use this, but it's helpful when testing refs */
Deeply render given React element and returns helpers to query the output. For convenience it also returns `react-test-renderer`'s `instance` and `renderer` objects, in case you need more control.
Returns a `RenderResult` object with following properties:
81
+
82
+
### `getByTestId: (testID: string)`
83
+
84
+
A method returning a `ReactTestInstance` with matching `testID` prop. Throws when no matches.
85
+
86
+
_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:_
A method returning an array of `ReactTestInstance`s with matching name – may be a string or React Element.
104
+
105
+
### `getByText: (text: string | RegExp)`
106
+
107
+
A method returning a `ReactTestInstance` with matching text – may be a string or regular expression. Throws when no matches.
108
+
109
+
### `getAllByText: (text: string | RegExp)`
110
+
111
+
A method returning an array of `ReactTestInstance`s with matching text – may be a string or regular expression.
112
+
113
+
### `getByProps: (props: { [propName: string]: any })`
114
+
115
+
A method returning a `ReactTestInstance` with matching props object. Throws when no matches.
116
+
117
+
### `getAllByProps: (props: { [propName: string]: any })`
118
+
119
+
A method returning an array of `ReactTestInstance`s with matching props object.
120
+
121
+
### `update: (element: React.Element<*>) => void`
122
+
123
+
Re-render the in-memory tree with a new root element. This simulates a React update at the root. If the new element has the same type and key as the previous element, the tree will be updated; otherwise, it will re-mount a new tree.
124
+
125
+
### `unmount: () => void`
126
+
127
+
Unmount the in-memory tree, triggering the appropriate lifecycle events
128
+
45
129
When using React context providers, like Redux Provider, you'll likely want to wrap rendered component with them. In such cases it's convenient to create your custom `render` method. [Follow this great guide on how to set this up](https://github.com/kentcdodds/react-testing-library#custom-render).
0 commit comments