Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 80dd480

Browse files
committed
Merge pull request facebook#4724 from AnSavvides/test-util-readability
Make definitions more readable & optional params more obvious (cherry picked from commit 77703db)
1 parent dcfbf80 commit 80dd480

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

docs/docs/10.4-test-utils.md

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ next: clone-with-props.html
1111
### Simulate
1212

1313
```javascript
14-
Simulate.{eventName}(DOMElement element, object eventData)
14+
Simulate.{eventName}(
15+
DOMElement element,
16+
[object eventData]
17+
)
1518
```
1619

1720
Simulate an event dispatch on a DOM node with optional `eventData` event data. **This is possibly the single most useful utility in `ReactTestUtils`.**
@@ -39,111 +42,147 @@ React.addons.TestUtils.Simulate.keyDown(node, {key: "Enter", keyCode: 13, which:
3942
### renderIntoDocument
4043

4144
```javascript
42-
ReactComponent renderIntoDocument(ReactElement instance)
45+
ReactComponent renderIntoDocument(
46+
ReactElement instance
47+
)
4348
```
4449

4550
Render a component into a detached DOM node in the document. **This function requires a DOM.**
4651

4752
### mockComponent
4853

4954
```javascript
50-
object mockComponent(function componentClass, string? mockTagName)
55+
object mockComponent(
56+
function componentClass,
57+
[string mockTagName]
58+
)
5159
```
5260

5361
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.
5462

5563
### isElement
5664

5765
```javascript
58-
boolean isElement(ReactElement element)
66+
boolean isElement(
67+
ReactElement element
68+
)
5969
```
6070

6171
Returns `true` if `element` is any ReactElement.
6272

6373
### isElementOfType
6474

6575
```javascript
66-
boolean isElementOfType(ReactElement element, function componentClass)
76+
boolean isElementOfType(
77+
ReactElement element,
78+
function componentClass
79+
)
6780
```
6881

6982
Returns `true` if `element` is a ReactElement whose type is of a React `componentClass`.
7083

7184
### isDOMComponent
7285

7386
```javascript
74-
boolean isDOMComponent(ReactComponent instance)
87+
boolean isDOMComponent(
88+
ReactComponent instance
89+
)
7590
```
7691

7792
Returns `true` if `instance` is a DOM component (such as a `<div>` or `<span>`).
7893

7994
### isCompositeComponent
8095

8196
```javascript
82-
boolean isCompositeComponent(ReactComponent instance)`
97+
boolean isCompositeComponent(
98+
ReactComponent instance
99+
)
83100
```
84101

85102
Returns `true` if `instance` is a composite component (created with `React.createClass()`).
86103

87104
### isCompositeComponentWithType
88105

89106
```javascript
90-
boolean isCompositeComponentWithType(ReactComponent instance, function componentClass)
107+
boolean isCompositeComponentWithType(
108+
ReactComponent instance,
109+
function componentClass
110+
)
91111
```
92112

93113
Returns `true` if `instance` is a composite component (created with `React.createClass()`) whose type is of a React `componentClass`.
94114

95115
### findAllInRenderedTree
96116

97117
```javascript
98-
array findAllInRenderedTree(ReactComponent tree, function test)
118+
array findAllInRenderedTree(
119+
ReactComponent tree,
120+
function test
121+
)
99122
```
100123

101124
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.
102125

103126
### scryRenderedDOMComponentsWithClass
104127

105128
```javascript
106-
array scryRenderedDOMComponentsWithClass(ReactComponent tree, string className)
129+
array scryRenderedDOMComponentsWithClass(
130+
ReactComponent tree, string className
131+
)
107132
```
108133

109134
Finds all instances of components in the rendered tree that are DOM components with the class name matching `className`.
110135

111136
### findRenderedDOMComponentWithClass
112137

113138
```javascript
114-
ReactComponent findRenderedDOMComponentWithClass(ReactComponent tree, string className)
139+
ReactComponent findRenderedDOMComponentWithClass(
140+
ReactComponent tree,
141+
string className
142+
)
115143
```
116144

117145
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.
118146

119147
### scryRenderedDOMComponentsWithTag
120148

121149
```javascript
122-
array scryRenderedDOMComponentsWithTag(ReactComponent tree, string tagName)
150+
array scryRenderedDOMComponentsWithTag(
151+
ReactComponent tree,
152+
string tagName
153+
)
123154
```
124155

125156
Finds all instances of components in the rendered tree that are DOM components with the tag name matching `tagName`.
126157

127158
### findRenderedDOMComponentWithTag
128159

129160
```javascript
130-
ReactComponent findRenderedDOMComponentWithTag(ReactComponent tree, string tagName)
161+
ReactComponent findRenderedDOMComponentWithTag(
162+
ReactComponent tree,
163+
string tagName
164+
)
131165
```
132166

133167
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.
134168

135169
### scryRenderedComponentsWithType
136170

137171
```javascript
138-
array scryRenderedComponentsWithType(ReactComponent tree, function componentClass)
172+
array scryRenderedComponentsWithType(
173+
ReactComponent tree,
174+
function componentClass
175+
)
139176
```
140177

141178
Finds all instances of components with type equal to `componentClass`.
142179

143180
### findRenderedComponentWithType
144181

145182
```javascript
146-
ReactComponent findRenderedComponentWithType(ReactComponent tree, function componentClass)
183+
ReactComponent findRenderedComponentWithType(
184+
ReactComponent tree, function componentClass
185+
)
147186
```
148187

149188
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.
@@ -160,7 +199,9 @@ ReactShallowRenderer createRenderer()
160199
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.
161200

162201
```javascript
163-
shallowRenderer.render(ReactElement element)
202+
shallowRenderer.render(
203+
ReactElement element
204+
)
164205
```
165206

166207
Similar to `React.render`.

0 commit comments

Comments
 (0)