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
Simulate an event dispatch on a DOM node with optional `eventData` event data. **This is possibly the single most useful utility in `ReactTestUtils`.**
Pass a mocked component module to this method to augment it with useful methods that allow it to be used as a dummy React component. Instead of rendering as usual, the component will become a simple `<div>` (or other tag if `mockTagName` is provided) containing any provided children.
54
62
55
63
### isElement
56
64
57
65
```javascript
58
-
boolean isElement(ReactElement element)
66
+
boolean isElement(
67
+
ReactElement element
68
+
)
59
69
```
60
70
61
71
Returns `true` if `element` is any ReactElement.
62
72
63
73
### isElementOfType
64
74
65
75
```javascript
66
-
boolean isElementOfType(ReactElement element, function componentClass)
76
+
boolean isElementOfType(
77
+
ReactElement element,
78
+
function componentClass
79
+
)
67
80
```
68
81
69
82
Returns `true` if `element` is a ReactElement whose type is of a React `componentClass`.
70
83
71
84
### isDOMComponent
72
85
73
86
```javascript
74
-
boolean isDOMComponent(ReactComponent instance)
87
+
boolean isDOMComponent(
88
+
ReactComponent instance
89
+
)
75
90
```
76
91
77
92
Returns `true` if `instance` is a DOM component (such as a `<div>` or `<span>`).
Returns `true` if `instance` is a composite component (created with `React.createClass()`).
86
103
87
104
### isCompositeComponentWithType
88
105
89
106
```javascript
90
-
boolean isCompositeComponentWithType(ReactComponent instance, function componentClass)
107
+
boolean isCompositeComponentWithType(
108
+
ReactComponent instance,
109
+
function componentClass
110
+
)
91
111
```
92
112
93
113
Returns `true` if `instance` is a composite component (created with `React.createClass()`) whose type is of a React `componentClass`.
94
114
95
115
### findAllInRenderedTree
96
116
97
117
```javascript
98
-
array findAllInRenderedTree(ReactComponent tree, function test)
118
+
array findAllInRenderedTree(
119
+
ReactComponent tree,
120
+
function test
121
+
)
99
122
```
100
123
101
124
Traverse all components in `tree` and accumulate all components where `test(component)` is `true`. This is not that useful on its own, but it's used as a primitive for other test utils.
Like `scryRenderedDOMComponentsWithClass()` but expects there to be one result, and returns that one result, or throws exception if there is any other number of matches besides one.
Like `scryRenderedDOMComponentsWithTag()` but expects there to be one result, and returns that one result, or throws exception if there is any other number of matches besides one.
134
168
135
169
### scryRenderedComponentsWithType
136
170
137
171
```javascript
138
-
array scryRenderedComponentsWithType(ReactComponent tree, function componentClass)
172
+
array scryRenderedComponentsWithType(
173
+
ReactComponent tree,
174
+
function componentClass
175
+
)
139
176
```
140
177
141
178
Finds all instances of components with type equal to `componentClass`.
142
179
143
180
### findRenderedComponentWithType
144
181
145
182
```javascript
146
-
ReactComponent findRenderedComponentWithType(ReactComponent tree, function componentClass)
183
+
ReactComponent findRenderedComponentWithType(
184
+
ReactComponent tree, function componentClass
185
+
)
147
186
```
148
187
149
188
Same as `scryRenderedComponentsWithType()` but expects there to be one result and returns that one result, or throws exception if there is any other number of matches besides one.
Call this in your tests to create a shallow renderer. You can think of this as a "place" to render the component you're testing, where it can respond to events and update itself.
0 commit comments