Fix some invalid uses of instances
Breaking this out of the other code mod.
Sebastian Markbage committed
Mar 13, 2014 at 16:23 UTC
9b427a322f87f2fd2f3c7227e04f848bbbcc622e
7 files changed
+134
-120
src/browser/server/ReactServerRendering.js
+2
-1
@@ -75,7 +75,8 @@ function renderComponentToStaticMarkup(component) {
75
transaction = ReactServerRenderingTransaction.getPooled(true);
76
77
return transaction.perform(function() {
78
- return component.mountComponent(id, transaction, 0);
78
+ var componentInstance = instantiateReactComponent(component);
79
+ return componentInstance.mountComponent(id, transaction, 0);
80
}, null);
81
} finally {
82
ReactServerRenderingTransaction.release(transaction);
src/browser/ui/dom/components/__tests__/ReactDOMInput-test.js
+22
-20
@@ -29,37 +29,32 @@ describe('ReactDOMInput', function() {
29
var ReactLink;
30
var ReactTestUtils;
31
32
- var renderTextInput;
33
-
32
beforeEach(function() {
33
React = require('React');
34
ReactLink = require('ReactLink');
35
ReactTestUtils = require('ReactTestUtils');
38
-
39
- renderTextInput = function(component) {
40
- var stub = ReactTestUtils.renderIntoDocument(component);
41
- var node = stub.getDOMNode();
42
- return node;
43
- };
36
});
37
38
it('should display `defaultValue` of number 0', function() {
39
var stub = <input type="text" defaultValue={0} />;
48
- var node = renderTextInput(stub);
40
+ stub = ReactTestUtils.renderIntoDocument(stub);
41
+ var node = stub.getDOMNode();
42
43
expect(node.value).toBe('0');
44
});
45
46
it('should display "true" for `defaultValue` of `true`', function() {
47
var stub = <input type="text" defaultValue={true} />;
55
- var node = renderTextInput(stub);
48
+ stub = ReactTestUtils.renderIntoDocument(stub);
49
+ var node = stub.getDOMNode();
50
51
expect(node.value).toBe('true');
52
});
53
54
it('should display "false" for `defaultValue` of `false`', function() {
55
var stub = <input type="text" defaultValue={false} />;
62
- var node = renderTextInput(stub);
56
+ stub = ReactTestUtils.renderIntoDocument(stub);
57
+ var node = stub.getDOMNode();
58
59
expect(node.value).toBe('false');
60
});
@@ -72,21 +67,24 @@ describe('ReactDOMInput', function() {
67
};
68
69
var stub = <input type="text" defaultValue={objToString} />;
75
- var node = renderTextInput(stub);
70
+ stub = ReactTestUtils.renderIntoDocument(stub);
71
+ var node = stub.getDOMNode();
72
73
expect(node.value).toBe('foobar');
74
});
75
76
it('should display `value` of number 0', function() {
77
var stub = <input type="text" value={0} />;
82
- var node = renderTextInput(stub);
78
+ stub = ReactTestUtils.renderIntoDocument(stub);
79
+ var node = stub.getDOMNode();
80
81
expect(node.value).toBe('0');
82
});
83
84
it('should allow setting `value` to `true`', function() {
85
var stub = <input type="text" value="yolo" />;
89
- var node = renderTextInput(stub);
86
+ stub = ReactTestUtils.renderIntoDocument(stub);
87
+ var node = stub.getDOMNode();
88
89
expect(node.value).toBe('yolo');
90
@@ -96,7 +94,8 @@ describe('ReactDOMInput', function() {
94
95
it("should allow setting `value` to `false`", function() {
96
var stub = <input type="text" value="yolo" />;
99
- var node = renderTextInput(stub);
97
+ stub = ReactTestUtils.renderIntoDocument(stub);
98
+ var node = stub.getDOMNode();
99
100
expect(node.value).toBe('yolo');
101
@@ -106,7 +105,8 @@ describe('ReactDOMInput', function() {
105
106
it('should allow setting `value` to `objToString`', function() {
107
var stub = <input type="text" value="foo" />;
109
- var node = renderTextInput(stub);
108
+ stub = ReactTestUtils.renderIntoDocument(stub);
109
+ var node = stub.getDOMNode();
110
111
expect(node.value).toBe('foo');
112
@@ -122,7 +122,8 @@ describe('ReactDOMInput', function() {
122
123
it('should properly control a value of number `0`', function() {
124
var stub = <input type="text" value={0} />;
125
- var node = renderTextInput(stub);
125
+ stub = ReactTestUtils.renderIntoDocument(stub);
126
+ var node = stub.getDOMNode();
127
128
node.value = 'giraffe';
129
ReactTestUtils.Simulate.change(node);
@@ -131,7 +132,8 @@ describe('ReactDOMInput', function() {
132
133
it('should not set a value for submit buttons unnecessarily', function() {
134
var stub = <input type="submit" />;
134
- var node = renderTextInput(stub);
135
+ stub = ReactTestUtils.renderIntoDocument(stub);
136
+ var node = stub.getDOMNode();
137
138
// The value shouldn't be '', or else the button will have no text; it
139
// should have the default "Submit" or "Submit Query" label
@@ -184,7 +186,7 @@ describe('ReactDOMInput', function() {
186
var link = new ReactLink('yolo', mocks.getMockFunction());
187
var instance = <input type="text" valueLink={link} />;
188
187
- React.renderComponent(instance, container);
189
+ instance = React.renderComponent(instance, container);
190
191
expect(instance.getDOMNode().value).toBe('yolo');
192
expect(link.value).toBe('yolo');
@@ -257,7 +259,7 @@ describe('ReactDOMInput', function() {
259
var link = new ReactLink(true, mocks.getMockFunction());
260
var instance = <input type="checkbox" checkedLink={link} />;
261
260
- React.renderComponent(instance, container);
262
+ instance = React.renderComponent(instance, container);
263
264
expect(instance.getDOMNode().checked).toBe(true);
265
expect(link.value).toBe(true);
src/browser/ui/dom/components/__tests__/ReactDOMSelect-test.js
+20
-18
@@ -28,18 +28,10 @@ describe('ReactDOMSelect', function() {
28
var ReactLink;
29
var ReactTestUtils;
30
31
- var renderSelect;
32
-
31
beforeEach(function() {
32
React = require('React');
33
ReactLink = require('ReactLink');
34
ReactTestUtils = require('ReactTestUtils');
37
-
38
- renderSelect = function(component) {
39
- var stub = ReactTestUtils.renderIntoDocument(component);
40
- var node = stub.getDOMNode();
41
- return node;
42
- };
35
});
36
37
it('should allow setting `defaultValue`', function() {
@@ -49,7 +41,8 @@ describe('ReactDOMSelect', function() {
41
<option value="giraffe">A giraffe!</option>
42
<option value="gorilla">A gorilla!</option>
43
</select>;
52
- var node = renderSelect(stub);
44
+ stub = ReactTestUtils.renderIntoDocument(stub);
45
+ var node = stub.getDOMNode();
46
47
expect(node.value).toBe('giraffe');
48
@@ -65,7 +58,8 @@ describe('ReactDOMSelect', function() {
58
<option value="giraffe">A giraffe!</option>
59
<option value="gorilla">A gorilla!</option>
60
</select>;
68
- var node = renderSelect(stub);
61
+ stub = ReactTestUtils.renderIntoDocument(stub);
62
+ var node = stub.getDOMNode();
63
64
expect(node.value).toBe('giraffe');
65
@@ -82,7 +76,8 @@ describe('ReactDOMSelect', function() {
76
<option value="giraffe">A giraffe!</option>
77
<option value="gorilla">A gorilla!</option>
78
</select>;
85
- var node = renderSelect(stub);
79
+ stub = ReactTestUtils.renderIntoDocument(stub);
80
+ var node = stub.getDOMNode();
81
82
expect(node.options[0].selected).toBe(false); // monkey
83
expect(node.options[1].selected).toBe(true); // giraffe
@@ -103,7 +98,8 @@ describe('ReactDOMSelect', function() {
98
<option value="giraffe">A giraffe!</option>
99
<option value="gorilla">A gorilla!</option>
100
</select>;
106
- var node = renderSelect(stub);
101
+ stub = ReactTestUtils.renderIntoDocument(stub);
102
+ var node = stub.getDOMNode();
103
104
expect(node.value).toBe('giraffe');
105
@@ -119,7 +115,8 @@ describe('ReactDOMSelect', function() {
115
<option value="giraffe">A giraffe!</option>
116
<option value="gorilla">A gorilla!</option>
117
</select>;
122
- var node = renderSelect(stub);
118
+ stub = ReactTestUtils.renderIntoDocument(stub);
119
+ var node = stub.getDOMNode();
120
121
expect(node.options[0].selected).toBe(false); // monkey
122
expect(node.options[1].selected).toBe(true); // giraffe
@@ -140,7 +137,8 @@ describe('ReactDOMSelect', function() {
137
<option value="2">two</option>
138
<option value="12">twelve</option>
139
</select>;
143
- var node = renderSelect(stub);
140
+ stub = ReactTestUtils.renderIntoDocument(stub);
141
+ var node = stub.getDOMNode();
142
143
expect(node.options[0].selected).toBe(false); // one
144
expect(node.options[1].selected).toBe(false); // two
@@ -161,7 +159,8 @@ describe('ReactDOMSelect', function() {
159
<option value="giraffe">A giraffe!</option>
160
<option value="gorilla">A gorilla!</option>
161
</select>;
164
- var node = renderSelect(stub);
162
+ stub = ReactTestUtils.renderIntoDocument(stub);
163
+ var node = stub.getDOMNode();
164
165
expect(node.options[0].selected).toBe(false); // monkey
166
expect(node.options[1].selected).toBe(true); // giraffe
@@ -183,7 +182,8 @@ describe('ReactDOMSelect', function() {
182
<option value="giraffe">A giraffe!</option>
183
<option value="gorilla">A gorilla!</option>
184
</select>;
186
- var node = renderSelect(stub);
185
+ stub = ReactTestUtils.renderIntoDocument(stub);
186
+ var node = stub.getDOMNode();
187
188
expect(node.options[0].selected).toBe(false); // monkey
189
expect(node.options[1].selected).toBe(true); // giraffe
@@ -204,7 +204,8 @@ describe('ReactDOMSelect', function() {
204
<option value="giraffe">A giraffe!</option>
205
<option value="gorilla">A gorilla!</option>
206
</select>;
207
- var node = renderSelect(stub);
207
+ stub = ReactTestUtils.renderIntoDocument(stub);
208
+ var node = stub.getDOMNode();
209
210
expect(node.options[0].selected).toBe(false); // monkey
211
expect(node.options[1].selected).toBe(true); // giraffe
@@ -227,7 +228,8 @@ describe('ReactDOMSelect', function() {
228
<option value="giraffe">A giraffe!</option>
229
<option value="gorilla">A gorilla!</option>
230
</select>;
230
- var node = renderSelect(stub);
231
+ stub = ReactTestUtils.renderIntoDocument(stub);
232
+ var node = stub.getDOMNode();
233
234
expect(node.options[0].selected).toBe(false); // monkey
235
expect(node.options[1].selected).toBe(true); // giraffe
src/browser/ui/dom/components/__tests__/ReactDOMTextarea-test.js
+30
-19
@@ -40,13 +40,14 @@ describe('ReactDOMTextarea', function() {
40
var node = stub.getDOMNode();
41
// Polyfilling the browser's quirky behavior.
42
node.value = node.innerHTML;
43
- return node;
43
+ return stub;
44
};
45
});
46
47
it('should allow setting `defaultValue`', function() {
48
var stub = <textarea defaultValue="giraffe" />;
49
- var node = renderTextarea(stub);
49
+ stub = renderTextarea(stub);
50
+ var node = stub.getDOMNode();
51
52
expect(node.value).toBe('giraffe');
53
@@ -57,14 +58,16 @@ describe('ReactDOMTextarea', function() {
58
59
it('should display `defaultValue` of number 0', function() {
60
var stub = <textarea defaultValue={0} />;
60
- var node = renderTextarea(stub);
61
+ stub = renderTextarea(stub);
62
+ var node = stub.getDOMNode();
63
64
expect(node.value).toBe('0');
65
});
66
67
it('should display "false" for `defaultValue` of `false`', function() {
68
var stub = <textarea type="text" defaultValue={false} />;
67
- var node = renderTextarea(stub);
69
+ stub = renderTextarea(stub);
70
+ var node = stub.getDOMNode();
71
72
expect(node.value).toBe('false');
73
});
@@ -77,21 +80,24 @@ describe('ReactDOMTextarea', function() {
80
};
81
82
var stub = <textarea type="text" defaultValue={objToString} />;
80
- var node = renderTextarea(stub);
83
+ stub = renderTextarea(stub);
84
+ var node = stub.getDOMNode();
85
86
expect(node.value).toBe('foobar');
87
});
88
89
it('should display `value` of number 0', function() {
90
var stub = <textarea value={0} />;
87
- var node = renderTextarea(stub);
91
+ stub = renderTextarea(stub);
92
+ var node = stub.getDOMNode();
93
94
expect(node.value).toBe('0');
95
});
96
97
it('should allow setting `value` to `giraffe`', function() {
98
var stub = <textarea value="giraffe" />;
94
- var node = renderTextarea(stub);
99
+ stub = renderTextarea(stub);
100
+ var node = stub.getDOMNode();
101
102
expect(node.value).toBe('giraffe');
103
@@ -101,7 +107,8 @@ describe('ReactDOMTextarea', function() {
107
108
it('should allow setting `value` to `true`', function() {
109
var stub = <textarea value="giraffe" />;
104
- var node = renderTextarea(stub);
110
+ stub = renderTextarea(stub);
111
+ var node = stub.getDOMNode();
112
113
expect(node.value).toBe('giraffe');
114
@@ -111,7 +118,8 @@ describe('ReactDOMTextarea', function() {
118
119
it('should allow setting `value` to `false`', function() {
120
var stub = <textarea value="giraffe" />;
114
- var node = renderTextarea(stub);
121
+ stub = renderTextarea(stub);
122
+ var node = stub.getDOMNode();
123
124
expect(node.value).toBe('giraffe');
125
@@ -121,7 +129,8 @@ describe('ReactDOMTextarea', function() {
129
130
it('should allow setting `value` to `objToString`', function() {
131
var stub = <textarea value="giraffe" />;
124
- var node = renderTextarea(stub);
132
+ stub = renderTextarea(stub);
133
+ var node = stub.getDOMNode();
134
135
expect(node.value).toBe('giraffe');
136
@@ -136,7 +145,8 @@ describe('ReactDOMTextarea', function() {
145
146
it('should properly control a value of number `0`', function() {
147
var stub = <textarea value={0} />;
139
- var node = renderTextarea(stub);
148
+ stub = renderTextarea(stub);
149
+ var node = stub.getDOMNode();
150
151
node.value = 'giraffe';
152
ReactTestUtils.Simulate.change(node);
@@ -147,7 +157,8 @@ describe('ReactDOMTextarea', function() {
157
spyOn(console, 'warn');
158
159
var stub = <textarea>giraffe</textarea>;
150
- var node = renderTextarea(stub);
160
+ stub = renderTextarea(stub);
161
+ var node = stub.getDOMNode();
162
163
expect(console.warn.argsForCall.length).toBe(1);
164
expect(node.value).toBe('giraffe');
@@ -159,14 +170,14 @@ describe('ReactDOMTextarea', function() {
170
171
it('should allow numbers as children', function() {
172
spyOn(console, 'warn');
162
- var node = renderTextarea(<textarea>{17}</textarea>);
173
+ var node = renderTextarea(<textarea>{17}</textarea>).getDOMNode();
174
expect(console.warn.argsForCall.length).toBe(1);
175
expect(node.value).toBe('17');
176
});
177
178
it('should allow booleans as children', function() {
179
spyOn(console, 'warn');
169
- var node = renderTextarea(<textarea>{false}</textarea>);
180
+ var node = renderTextarea(<textarea>{false}</textarea>).getDOMNode();
181
expect(console.warn.argsForCall.length).toBe(1);
182
expect(node.value).toBe('false');
183
});
@@ -178,7 +189,7 @@ describe('ReactDOMTextarea', function() {
189
return "sharkswithlasers";
190
}
191
};
181
- var node = renderTextarea(<textarea>{obj}</textarea>);
192
+ var node = renderTextarea(<textarea>{obj}</textarea>).getDOMNode();
193
expect(console.warn.argsForCall.length).toBe(1);
194
expect(node.value).toBe('sharkswithlasers');
195
});
@@ -194,12 +205,12 @@ describe('ReactDOMTextarea', function() {
205
206
expect(console.warn.argsForCall.length).toBe(1);
207
197
- var stub;
208
+ var node;
209
expect(function() {
199
- stub = renderTextarea(<textarea><strong /></textarea>);
210
+ node = renderTextarea(<textarea><strong /></textarea>).getDOMNode();
211
}).not.toThrow();
212
202
- expect(stub.value).toBe('[object Object]');
213
+ expect(node.value).toBe('[object Object]');
214
215
expect(console.warn.argsForCall.length).toBe(2);
216
});
@@ -209,7 +220,7 @@ describe('ReactDOMTextarea', function() {
220
var link = new ReactLink('yolo', mocks.getMockFunction());
221
var instance = <textarea valueLink={link} />;
222
212
- React.renderComponent(instance, container);
223
+ instance = React.renderComponent(instance, container);
224
225
expect(instance.getDOMNode().value).toBe('yolo');
226
expect(link.value).toBe('yolo');
src/core/__tests__/ReactBind-test.js
+3
-3
@@ -62,13 +62,13 @@ describe('autobinding', function() {
62
63
var instance1 = <TestBindComponent />;
64
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
65
- var rendered1 = reactComponentExpect(instance1)
65
+ var rendered1 = reactComponentExpect(mountedInstance1)
66
.expectRenderedChild()
67
.instance();
68
69
var instance2 = <TestBindComponent />;
70
var mountedInstance2 = ReactTestUtils.renderIntoDocument(instance2);
71
- var rendered2 = reactComponentExpect(instance2)
71
+ var rendered2 = reactComponentExpect(mountedInstance2)
72
.expectRenderedChild()
73
.instance();
74
@@ -123,7 +123,7 @@ describe('autobinding', function() {
123
124
var instance1 = <TestBindComponent />;
125
var mountedInstance1 = ReactTestUtils.renderIntoDocument(instance1);
126
- var rendered1 = reactComponentExpect(instance1)
126
+ var rendered1 = reactComponentExpect(mountedInstance1)
127
.expectRenderedChild()
128
.instance();
129
src/core/__tests__/ReactComponentLifeCycle-test.js
+10
-10
@@ -108,11 +108,11 @@ describe('ReactComponentLifeCycle', function() {
108
}
109
});
110
var instance = <StatefulComponent />;
111
- ReactTestUtils.renderIntoDocument(instance);
111
+ instance = ReactTestUtils.renderIntoDocument(instance);
112
instance.addAnotherField();
113
expect(instance.state.aField).toBe('asdf');
114
instance.unmountComponent();
115
- ReactTestUtils.renderIntoDocument(instance);
115
+ instance = ReactTestUtils.renderIntoDocument(instance);
116
expect(typeof instance.state.aField).toBe('undefined');
117
});
118
@@ -157,7 +157,7 @@ describe('ReactComponentLifeCycle', function() {
157
});
158
159
var instance = <SwitcherParent />;
160
- ReactTestUtils.renderIntoDocument(instance);
160
+ instance = ReactTestUtils.renderIntoDocument(instance);
161
expect(_testJournal).toEqual([
162
'SwitcherParent:getInitialState',
163
'SwitcherParent:onDOMReady',
@@ -180,11 +180,11 @@ describe('ReactComponentLifeCycle', function() {
180
}
181
});
182
var instance = <StatefulComponent />;
183
- ReactTestUtils.renderIntoDocument(instance);
183
+ instance = ReactTestUtils.renderIntoDocument(instance);
184
instance.addAnotherField();
185
expect(instance.state.aField).toBe('asdf');
186
instance.unmountComponent();
187
- ReactTestUtils.renderIntoDocument(instance);
187
+ instance = ReactTestUtils.renderIntoDocument(instance);
188
expect(instance.state).toBe(null);
189
});
190
@@ -203,7 +203,7 @@ describe('ReactComponentLifeCycle', function() {
203
});
204
var instance = <StatefulComponent />;
205
expect(function() {
206
- ReactTestUtils.renderIntoDocument(instance);
206
+ instance = ReactTestUtils.renderIntoDocument(instance);
207
}).toThrow();
208
});
209
@@ -220,7 +220,7 @@ describe('ReactComponentLifeCycle', function() {
220
});
221
var instance = <StatefulComponent />;
222
expect(function() {
223
- ReactTestUtils.renderIntoDocument(instance);
223
+ instance = ReactTestUtils.renderIntoDocument(instance);
224
}).not.toThrow();
225
});
226
@@ -239,7 +239,7 @@ describe('ReactComponentLifeCycle', function() {
239
});
240
var instance = <StatefulComponent />;
241
expect(function() {
242
- ReactTestUtils.renderIntoDocument(instance);
242
+ instance = ReactTestUtils.renderIntoDocument(instance);
243
}).not.toThrow();
244
245
// The return value of getInitialState overrides anything from setState
@@ -403,7 +403,7 @@ describe('ReactComponentLifeCycle', function() {
403
valueToUseInOnDOMReady="goodbye"
404
/>;
405
expect(function() {
406
- ReactTestUtils.renderIntoDocument(instance);
406
+ instance = ReactTestUtils.renderIntoDocument(instance);
407
}).toThrow(
408
'Invariant Violation: replaceProps(...): You called `setProps` or ' +
409
'`replaceProps` on a component with a parent. This is an anti-pattern ' +
@@ -497,7 +497,7 @@ describe('ReactComponentLifeCycle', function() {
497
valueToUseInitially="hello"
498
valueToUseInOnDOMReady="goodbye"
499
/>;
500
- ReactTestUtils.renderIntoDocument(instance);
500
+ instance = ReactTestUtils.renderIntoDocument(instance);
501
expect(instance.state.stateField).toBe('goodbye');
502
});
503
src/core/__tests__/ReactCompositeComponent-test.js
+47
-49
@@ -92,7 +92,7 @@ describe('ReactCompositeComponent', function() {
92
93
it('should support rendering to different child types over time', function() {
94
var instance = <MorphingComponent />;
95
- ReactTestUtils.renderIntoDocument(instance);
95
+ instance = ReactTestUtils.renderIntoDocument(instance);
96
97
reactComponentExpect(instance)
98
.expectRenderedChild()
@@ -111,7 +111,7 @@ describe('ReactCompositeComponent', function() {
111
112
it('should react to state changes from callbacks', function() {
113
var instance = <MorphingComponent />;
114
- ReactTestUtils.renderIntoDocument(instance);
114
+ instance = ReactTestUtils.renderIntoDocument(instance);
115
116
var renderedChild = reactComponentExpect(instance)
117
.expectRenderedChild()
@@ -125,7 +125,7 @@ describe('ReactCompositeComponent', function() {
125
126
it('should rewire refs when rendering to different child types', function() {
127
var instance = <MorphingComponent />;
128
- ReactTestUtils.renderIntoDocument(instance);
128
+ instance = ReactTestUtils.renderIntoDocument(instance);
129
130
reactComponentExpect(instance.refs.x).toBeDOMComponentWithTag('a');
131
instance._toggleActivatedState();
@@ -136,7 +136,7 @@ describe('ReactCompositeComponent', function() {
136
137
it('should not cache old DOM nodes when switching constructors', function() {
138
var instance = <ChildUpdates renderAnchor={true} anchorClassOn={false}/>;
139
- ReactTestUtils.renderIntoDocument(instance);
139
+ instance = ReactTestUtils.renderIntoDocument(instance);
140
instance.setProps({anchorClassOn: true}); // Warm any cache
141
instance.setProps({renderAnchor: false}); // Clear out the anchor
142
// rerender
@@ -168,38 +168,37 @@ describe('ReactCompositeComponent', function() {
168
});
169
var instance = <ComponentClass />;
170
171
- // These are controversial assertions for now, they just exist
172
- // because existing code depends on these assumptions.
173
- // These are expected to log a warning. This use case will be deprecated.
171
+ // Next, prove that once mounted, the scope is bound correctly to the actual
172
+ // component.
173
+ var mountedInstance = ReactTestUtils.renderIntoDocument(instance);
174
+
175
expect(function() {
175
- instance.methodToBeExplicitlyBound.bind(instance)();
176
+ mountedInstance.methodToBeExplicitlyBound.bind(instance)();
177
}).not.toThrow();
178
expect(function() {
178
- instance.methodAutoBound();
179
+ mountedInstance.methodAutoBound();
180
}).not.toThrow();
181
expect(function() {
181
- instance.methodExplicitlyNotBound();
182
+ mountedInstance.methodExplicitlyNotBound();
183
}).not.toThrow();
184
184
- // Next, prove that once mounted, the scope is bound correctly to the actual
185
- // component.
186
- var mountedInstance = ReactTestUtils.renderIntoDocument(instance);
187
- expect(console.warn.argsForCall.length).toBe(3);
188
- // This will result in a warning that has already been issued before.
189
- var explicitlyBound = instance.methodToBeExplicitlyBound.bind(instance);
190
- expect(console.warn.argsForCall.length).toBe(3);
191
- var autoBound = instance.methodAutoBound;
192
- var explicitlyNotBound = instance.methodExplicitlyNotBound;
185
+ expect(console.warn.argsForCall.length).toBe(1);
186
+ var explicitlyBound = mountedInstance.methodToBeExplicitlyBound.bind(
187
+ mountedInstance
188
+ );
189
+ expect(console.warn.argsForCall.length).toBe(2);
190
+ var autoBound = mountedInstance.methodAutoBound;
191
+ var explicitlyNotBound = mountedInstance.methodExplicitlyNotBound;
192
193
var context = {};
194
expect(explicitlyBound.call(context)).toBe(mountedInstance);
195
expect(autoBound.call(context)).toBe(mountedInstance);
196
expect(explicitlyNotBound.call(context)).toBe(context);
197
199
- expect(explicitlyBound.call(instance)).toBe(mountedInstance);
200
- expect(autoBound.call(instance)).toBe(mountedInstance);
198
+ expect(explicitlyBound.call(mountedInstance)).toBe(mountedInstance);
199
+ expect(autoBound.call(mountedInstance)).toBe(mountedInstance);
200
// This one is the weird one
202
- expect(explicitlyNotBound.call(instance)).toBe(mountedInstance);
201
+ expect(explicitlyNotBound.call(mountedInstance)).toBe(mountedInstance);
202
203
});
204
@@ -214,15 +213,15 @@ describe('ReactCompositeComponent', function() {
213
});
214
215
var instance1 = <Component />;
217
- ReactTestUtils.renderIntoDocument(instance1);
216
+ instance1 = ReactTestUtils.renderIntoDocument(instance1);
217
reactComponentExpect(instance1).scalarPropsEqual({key: 'testKey'});
218
219
var instance2 = <Component key={undefined} />;
221
- ReactTestUtils.renderIntoDocument(instance2);
220
+ instance2 = ReactTestUtils.renderIntoDocument(instance2);
221
reactComponentExpect(instance2).scalarPropsEqual({key: 'testKey'});
222
223
var instance3 = <Component key={null} />;
225
- ReactTestUtils.renderIntoDocument(instance3);
224
+ instance3 = ReactTestUtils.renderIntoDocument(instance3);
225
reactComponentExpect(instance3).scalarPropsEqual({key: null});
226
});
227
@@ -238,7 +237,7 @@ describe('ReactCompositeComponent', function() {
237
238
var inputProps = {};
239
var instance1 = Component(inputProps);
241
- ReactTestUtils.renderIntoDocument(instance1);
240
+ instance1 = ReactTestUtils.renderIntoDocument(instance1);
241
expect(instance1.props.key).toBe('testKey');
242
243
// We don't mutate the input, just in case the caller wants to do something
@@ -410,7 +409,7 @@ describe('ReactCompositeComponent', function() {
409
'mounted or mounting components.'
410
);
411
413
- React.renderComponent(instance, container);
412
+ instance = React.renderComponent(instance, container);
413
expect(function() {
414
instance.forceUpdate();
415
}).not.toThrow();
@@ -435,7 +434,7 @@ describe('ReactCompositeComponent', function() {
434
expect(ReactCurrentOwner.current).toBe(null);
435
436
expect(function() {
438
- ReactTestUtils.renderIntoDocument(instance);
437
+ instance = ReactTestUtils.renderIntoDocument(instance);
438
}).toThrow();
439
440
expect(ReactCurrentOwner.current).toBe(null);
@@ -457,7 +456,7 @@ describe('ReactCompositeComponent', function() {
456
}
457
});
458
var instance = <Component />;
460
- ReactTestUtils.renderIntoDocument(instance);
459
+ instance = ReactTestUtils.renderIntoDocument(instance);
460
expect(instance.state.component).toBe(true);
461
expect(instance.state.mixin).toBe(true);
462
});
@@ -479,7 +478,7 @@ describe('ReactCompositeComponent', function() {
478
});
479
var instance = <Component />;
480
expect(function() {
482
- ReactTestUtils.renderIntoDocument(instance);
481
+ instance = ReactTestUtils.renderIntoDocument(instance);
482
}).toThrow(
483
'Invariant Violation: mergeObjectsWithNoDuplicateKeys(): ' +
484
'Tried to merge two objects with the same key: x'
@@ -498,7 +497,7 @@ describe('ReactCompositeComponent', function() {
497
}
498
});
499
var instance = <Component />;
501
- ReactTestUtils.renderIntoDocument(instance);
500
+ instance = ReactTestUtils.renderIntoDocument(instance);
501
expect(instance.state.occupation).toEqual('clown');
502
});
503
@@ -514,7 +513,7 @@ describe('ReactCompositeComponent', function() {
513
});
514
var instance = <Component />;
515
expect(function() {
517
- ReactTestUtils.renderIntoDocument(instance);
516
+ instance = ReactTestUtils.renderIntoDocument(instance);
517
}).toThrow(
518
'Invariant Violation: Component.getInitialState(): ' +
519
'must return an object or null'
@@ -559,7 +558,7 @@ describe('ReactCompositeComponent', function() {
558
).not.toThrow();
559
560
instance = <Component />;
562
- ReactTestUtils.renderIntoDocument(instance);
561
+ instance = ReactTestUtils.renderIntoDocument(instance);
562
expect(instance.state).toEqual({foo: 'bar'});
563
564
// Also the other way round should work
@@ -582,7 +581,7 @@ describe('ReactCompositeComponent', function() {
581
).not.toThrow();
582
583
instance = <Component />;
585
- ReactTestUtils.renderIntoDocument(instance);
584
+ instance = ReactTestUtils.renderIntoDocument(instance);
585
expect(instance.state).toEqual({foo: 'bar'});
586
587
// Multiple mixins should be fine too
@@ -600,7 +599,7 @@ describe('ReactCompositeComponent', function() {
599
).not.toThrow();
600
601
instance = <Component />;
603
- ReactTestUtils.renderIntoDocument(instance);
602
+ instance = ReactTestUtils.renderIntoDocument(instance);
603
expect(instance.state).toEqual({foo: 'bar', x: true});
604
});
605
@@ -616,7 +615,7 @@ describe('ReactCompositeComponent', function() {
615
}
616
});
617
var instance = <Component />;
619
- ReactTestUtils.renderIntoDocument(instance);
618
+ instance = ReactTestUtils.renderIntoDocument(instance);
619
expect(instance.state.occupation).toEqual('clown');
620
});
621
@@ -632,7 +631,7 @@ describe('ReactCompositeComponent', function() {
631
});
632
var instance = <Component />;
633
expect(function() {
635
- ReactTestUtils.renderIntoDocument(instance);
634
+ instance = ReactTestUtils.renderIntoDocument(instance);
635
}).toThrow(
636
'Invariant Violation: Component.getInitialState(): ' +
637
'must return an object or null'
@@ -803,8 +802,7 @@ describe('ReactCompositeComponent', function() {
802
},
803
804
render: function() {
806
- childInstance = <Child />;
807
- return childInstance;
805
+ return <Child />;
806
}
807
});
808
@@ -825,8 +823,8 @@ describe('ReactCompositeComponent', function() {
823
},
824
825
render: function() {
828
- grandchildInstance = <Grandchild />;
829
- return grandchildInstance;
826
+ childInstance = this;
827
+ return <Grandchild />;
828
}
829
});
830
@@ -837,12 +835,12 @@ describe('ReactCompositeComponent', function() {
835
},
836
837
render: function() {
838
+ grandchildInstance = this;
839
return <div />;
840
}
841
});
842
844
- var instance = <Parent />;
845
- ReactTestUtils.renderIntoDocument(instance);
843
+ ReactTestUtils.renderIntoDocument(<Parent />);
844
reactComponentExpect(childInstance).scalarContextEqual({foo: 'bar', depth: 0});
845
reactComponentExpect(grandchildInstance).scalarContextEqual({foo: 'bar', depth: 1});
846
});
@@ -940,7 +938,7 @@ describe('ReactCompositeComponent', function() {
938
var instance = React.withContext({foo: 'abc', bar: 123}, function() {
939
return <Component />;
940
});
943
- ReactTestUtils.renderIntoDocument(instance);
941
+ instance = ReactTestUtils.renderIntoDocument(instance);
942
reactComponentExpect(instance).scalarContextEqual({foo: 'abc'});
943
});
944
@@ -997,7 +995,7 @@ describe('ReactCompositeComponent', function() {
995
});
996
997
var instance = <Parent foo="abc" />;
1000
- ReactTestUtils.renderIntoDocument(instance);
998
+ instance = ReactTestUtils.renderIntoDocument(instance);
999
instance.replaceProps({foo: "def"});
1000
expect(actualComponentWillReceiveProps).toEqual({foo: 'def'});
1001
expect(actualShouldComponentUpdate).toEqual({foo: 'def'});
@@ -1019,7 +1017,7 @@ describe('ReactCompositeComponent', function() {
1017
}
1018
});
1019
var instance = <Component />;
1022
- ReactTestUtils.renderIntoDocument(instance);
1020
+ instance = ReactTestUtils.renderIntoDocument(instance);
1021
expect(instance.constructor.abc).toBe('def');
1022
expect(Component.abc).toBe('def');
1023
expect(instance.constructor.def).toBe(0);
@@ -1048,7 +1046,7 @@ describe('ReactCompositeComponent', function() {
1046
}
1047
});
1048
var instance = <Component />;
1051
- ReactTestUtils.renderIntoDocument(instance);
1049
+ instance = ReactTestUtils.renderIntoDocument(instance);
1050
expect(instance.constructor.foo).toBe('bar');
1051
expect(Component.foo).toBe('bar');
1052
expect(instance.constructor.abc).toBe('def');
@@ -1132,7 +1130,7 @@ describe('ReactCompositeComponent', function() {
1130
}
1131
});
1132
var instance = <Component />;
1135
- ReactTestUtils.renderIntoDocument(instance);
1133
+ instance = ReactTestUtils.renderIntoDocument(instance);
1134
});
1135
1136
it('should include the mixin keys in even if their values are falsy',
@@ -1153,7 +1151,7 @@ describe('ReactCompositeComponent', function() {
1151
}
1152
});
1153
var instance = <Component />;
1156
- ReactTestUtils.renderIntoDocument(instance);
1154
+ instance = ReactTestUtils.renderIntoDocument(instance);
1155
});
1156
1157
it('should warn if an umounted component is touched', function() {