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
Returns a `RenderResult` object with following properties:
32
+
Returns a `RenderResult` object with [Queries](./Queries.md) and following helpers:
33
33
34
-
### `getByTestId: (testID: string)`
34
+
### `update`
35
35
36
-
A method returning a `ReactTestInstance` with matching `testID` prop. Throws when no matches.
37
-
38
-
_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:_
36
+
_Also available under `rerender` alias_
39
37
40
-
```jsx
41
-
type ReactTestInstance = {
42
-
type: string |Function,
43
-
props: { [propName: string]: any },
44
-
parent:null| ReactTestInstance,
45
-
children:Array<ReactTestInstance | string>,
46
-
};
38
+
```ts
39
+
update(element: React.Element<any>): void
40
+
rerender(element: React.Element<any>): void
47
41
```
48
42
49
-
### `getByText: (text: string | RegExp)`
50
-
51
-
A method returning a `ReactTestInstance` with matching text – may be a string or regular expression. Throws when no matches.
52
-
53
-
This method will join `<Text>` siblings to find matches, similarly to [how React Native handles these components](https://facebook.github.io/react-native/docs/text#containers). This will allow for querying for strings that will be visually rendered together, but may be semantically separate React components.
54
-
55
-
### `getAllByText: (text: string | RegExp)`
56
-
57
-
A method returning an array of `ReactTestInstance`s with matching text – may be a string or regular expression.
A method returning a `ReactTestInstance` for a `TextInput` with a matching placeholder – may be a string or regular expression. Throws when no matches.
A method returning a `ReactTestInstance` with matching a React component type. Throws when no matches.
90
-
91
-
> This method has been **deprecated** because using it results in fragile tests that may break between minor React Native versions. It will be removed in next major release (v2.0). Use [`getByType`](#getbytype-type-reactcomponenttype) instead.
A method returning an array of `ReactTestInstance`s with matching a React component type.
96
-
97
-
> This method has been **deprecated** because using it results in fragile tests that may break between minor React Native versions. It will be removed in next major release (v2.0). Use [`getAllByType`](#getallbytype-type-reactcomponenttype) instead.
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. This is useful when testing for `componentDidUpdate` behavior, by passing updated props to the component.
Unmount the in-memory tree, triggering the appropriate lifecycle events
110
54
111
55
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).
112
56
113
-
### `debug: (message?: string) => void`
57
+
### `debug`
58
+
59
+
```ts
60
+
debug(message?:string): void
61
+
```
114
62
115
63
Prints deeply rendered component passed to `render` with optional message on top. Uses [debug.deep](#debug) under the hood, but it's easier to use.
116
64
@@ -133,11 +81,15 @@ optional message
133
81
</TouchableOpacity>
134
82
```
135
83
136
-
### `debug.shallow: (message?: string) => void`
84
+
####`debug.shallow`
137
85
138
86
Prints shallowly rendered component passed to `render` with optional message on top. Uses [debug.shallow](#debug) under the hood, but it's easier to use.
139
87
140
-
### `toJSON: () => ?ReactTestRendererJSON`
88
+
### `toJSON`
89
+
90
+
```ts
91
+
toJSON(): ReactTestRendererJSON|null
92
+
```
141
93
142
94
Get the rendered component JSON representation, e.g. for snapshot testing.
143
95
@@ -158,24 +110,27 @@ test('Component has a structure', () => {
Invokes a given event handler (whether native or custom) on the element, bubbling to the root of the rendered tree. The three most common events (`press`, `changeText`, and `scroll`) have been aliased for convenience.
Invokes named event handler on the element or parent element in the tree. For better readability, `fireEvent` strips the `on` part of the handler prop name, so it will fire `onMyCustomEvent` when `myCustomEvent` is passed as `eventName`.
119
+
Invokes a given event handler (whether native or custom) on the element, bubbling to the root of the rendered tree.
> `getBy` queries are shown by default in the [query documentation](#queries)
9
+
> below.
10
+
11
+
### getBy
12
+
13
+
`getBy*` queries returns the first matching node for a query, and throws an
14
+
error if no elements match.
15
+
16
+
### getAllBy
17
+
18
+
`getAllBy*` queries return an array of all matching nodes for a query, and
19
+
throws an error if no elements match.
20
+
21
+
### queryBy
22
+
23
+
`queryBy*` queries returns the first matching node for a query, and return
24
+
`null` if no elements match. This is useful for asserting an element is not
25
+
present.
26
+
27
+
### queryAllBy
28
+
29
+
`queryAllBy*` queries return an array of all matching nodes for a query, and
30
+
return an empty array (`[]`) if no elements match.
31
+
32
+
## Queries
33
+
34
+
_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:_
Returns a `ReactTestInstance` with matching text – may be a string or regular expression.
50
+
51
+
This method will join `<Text>` siblings to find matches, similarly to [how React Native handles these components](https://facebook.github.io/react-native/docs/text#containers). This will allow for querying for strings that will be visually rendered together, but may be semantically separate React components.
> Use sparingly and responsibly, escape hatches here
89
+
90
+
`render` from `react-native-testing-library` exposes additional queries that **should not be used in component integration testing**, but some users (like component library creators) interested in unit testing some components may find helpful.
91
+
92
+
<details>
93
+
<summary>Queries helpful in unit testing</summary>
94
+
95
+
The interface is the same as for other queries, but we won't provide full names so that they're harder to find by search engines.
96
+
97
+
### `ByType`
98
+
99
+
> Note: added in v1.4
100
+
101
+
A method returning a `ReactTestInstance` with matching a React component type. Throws when no matches.
102
+
103
+
### `ByProps`
104
+
105
+
A method returning a `ReactTestInstance` with matching props object
106
+
107
+
### `ByName`
108
+
109
+
> This method has been **deprecated** because using it results in fragile tests that may break between minor React Native versions. **DON'T USE IT**. It will be removed in next major release (v2.0). Use [`getByTestId`](#bytestid) instead. It's listed here only for back-compat purposes for early adopters of the library
110
+
111
+
A method returning a `ReactTestInstance` with matching a React component type. Throws when no matches.
0 commit comments