@samitouri / QOS-React-2 / commits / 76f5453cc7

Mention shallow rendering's limitations

Also, move it to the bottom of the test utils documentation and mention that it's experimental.

Scott Feeney committed Jan 27, 2015 at 17:09 UTC 76f5453cc7551d0daa9a5a2f63b6ec06778a9383
1 file changed +43 -40
docs/docs/10.4-test-utils.md
+43 -40
@@ -8,46 +8,6 @@ next: clone-with-props.html
8
9 `React.addons.TestUtils` makes it easy to test React components in the testing framework of your choice (we use [Jest](http://facebook.github.io/jest/)).
10
11 -## Shallow rendering
12 -
13 -Shallow rendering allows you to render a component "one level deep" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM.
14 -
15 -```javascript
16 -ReactShallowRenderer createRenderer()
17 -```
18 -
19 -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.
20 -
21 -```javascript
22 -shallowRenderer.render(ReactElement element)
23 -```
24 -
25 -Similar to `React.render`.
26 -
27 -```javascript
28 -ReactComponent shallowRenderer.getRenderOutput()
29 -```
30 -
31 -After render has been called, returns shallowly rendered output. You can then begin to assert facts about the output. For example, if your component's render method returns:
32 -
33 -```javascript
34 -<div>
35 - <span className="heading">Title</span>
36 - <Subcomponent foo="bar" />
37 -</div>
38 -```
39 -
40 -Then you can assert:
41 -
42 -```javascript
43 -result = renderer.getRenderOutput();
44 -expect(result.type).toBe('div');
45 -expect(result.props.children).toEqual([
46 - <span className="heading">Title</span>
47 - <Subcomponent foo="bar" />
48 -]);
49 -```
50 -
11 ### Simulate
12
13 ```javascript
@@ -170,3 +130,46 @@ ReactComponent findRenderedComponentWithType(ReactComponent tree, function compo
130 ```
131
132 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.
133 +
134 +
135 +## Shallow rendering
136 +
137 +Shallow rendering is an experimental feature that lets you render a component "one level deep" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM.
138 +
139 +```javascript
140 +ReactShallowRenderer createRenderer()
141 +```
142 +
143 +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.
144 +
145 +```javascript
146 +shallowRenderer.render(ReactElement element)
147 +```
148 +
149 +Similar to `React.render`.
150 +
151 +```javascript
152 +ReactComponent shallowRenderer.getRenderOutput()
153 +```
154 +
155 +After render has been called, returns shallowly rendered output. You can then begin to assert facts about the output. For example, if your component's render method returns:
156 +
157 +```javascript
158 +<div>
159 + <span className="heading">Title</span>
160 + <Subcomponent foo="bar" />
161 +</div>
162 +```
163 +
164 +Then you can assert:
165 +
166 +```javascript
167 +result = renderer.getRenderOutput();
168 +expect(result.type).toBe('div');
169 +expect(result.props.children).toEqual([
170 + <span className="heading">Title</span>
171 + <Subcomponent foo="bar" />
172 +]);
173 +```
174 +
175 +Shallow testing currently has some limitations, namely not supporting refs. We're releasing this feature early and would appreciate the React community's feedback on how it should evolve.