@samitouri / QOS-React-2 / commits / 2b68ea21ee

Removed most uses of setProps in unit tests

Picked from 721fe7354142c866db2ebcc727a2472a3f3e0cc6.

Ben Alpert committed Jul 3, 2015 at 10:20 UTC 2b68ea21ee27485aee3dc67707626f47ccd12678
5 files changed +39 -31
src/isomorphic/classic/__tests__/ReactContextValidator-test.js
+3 -3
@@ -121,9 +121,9 @@ describe('ReactContextValidator', function() {
121 },
122 });
123
124 - var instance = <Parent foo="abc" />;
125 - instance = ReactTestUtils.renderIntoDocument(instance);
126 - instance.replaceProps({foo: 'def'});
124 + var container = document.createElement('div');
125 + React.render(<Parent foo="abc" />, container);
126 + React.render(<Parent foo="def" />, container);
127 expect(actualComponentWillReceiveProps).toEqual({foo: 'def'});
128 expect(actualShouldComponentUpdate).toEqual({foo: 'def'});
129 expect(actualComponentWillUpdate).toEqual({foo: 'def'});
src/renderers/shared/reconciler/__tests__/ReactComponentLifeCycle-test.js
+10 -16
@@ -512,24 +512,18 @@ describe('ReactComponentLifeCycle', function() {
512 },
513 });
514
515 - var instance = ReactTestUtils.renderIntoDocument(
516 - <Component text="uno" tooltipText="one" />
515 + var container = document.createElement('div');
516 + React.render(
517 + <Component text="uno" tooltipText="one" />,
518 + container
519 );
520
521 // Since `instance` is a root component, we can set its props. This also
522 // makes Tooltip rerender the tooltip component, which shouldn't throw.
521 - instance.setProps({text: 'dos', tooltipText: 'two'});
522 - });
523 -
524 - it('should not allow setProps() called on an unmounted element',
525 - function() {
526 - var PropsToUpdate = React.createClass({
527 - render: function() {
528 - return <div className={this.props.value} ref="theSimpleComponent" />;
529 - },
530 - });
531 - var instance = <PropsToUpdate value="hello" />;
532 - expect(instance.setProps).not.toBeDefined();
523 + React.render(
524 + <Component text="dos" tooltipText="two" />,
525 + container
526 + );
527 });
528
529 it('should allow state updates in componentDidMount', function() {
@@ -595,7 +589,7 @@ describe('ReactComponentLifeCycle', function() {
589
590 var container = document.createElement('div');
591 log = [];
598 - var instance = React.render(<Outer x={17} />, container);
592 + React.render(<Outer x={17} />, container);
593 expect(log).toEqual([
594 'outer componentWillMount',
595 'inner componentWillMount',
@@ -604,7 +598,7 @@ describe('ReactComponentLifeCycle', function() {
598 ]);
599
600 log = [];
607 - instance.setProps({x: 42});
601 + React.render(<Outer x={42} />, container);
602 expect(log).toEqual([
603 'outer componentWillReceiveProps',
604 'outer shouldComponentUpdate',
src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js
+3 -2
@@ -935,7 +935,8 @@ describe('ReactCompositeComponent', function() {
935 },
936 });
937
938 - var comp = ReactTestUtils.renderIntoDocument(<Component flipped={false} />);
938 + var container = document.createElement('div');
939 + var comp = React.render(<Component flipped={false} />, container);
940 expect(React.findDOMNode(comp.refs.static0).textContent).toBe('A');
941 expect(React.findDOMNode(comp.refs.static1).textContent).toBe('B');
942
@@ -946,7 +947,7 @@ describe('ReactCompositeComponent', function() {
947
948 // When flipping the order, the refs should update even though the actual
949 // contents do not
949 - comp.setProps({flipped: true});
950 + React.render(<Component flipped={true} />, container);
951 expect(React.findDOMNode(comp.refs.static0).textContent).toBe('B');
952 expect(React.findDOMNode(comp.refs.static1).textContent).toBe('A');
953
src/renderers/shared/reconciler/__tests__/ReactCompositeComponentState-test.js
+3 -2
@@ -138,8 +138,9 @@ describe('ReactCompositeComponent-state', function() {
138 this.peekAtState('initial-callback');
139 }
140 );
141 - instance.setProps(
142 - {nextColor: 'green'},
141 + React.render(
142 + <TestComponent stateListener={stateListener} nextColor="green" />,
143 + container,
144 instance.peekAtCallback('setProps')
145 );
146 instance.setFavoriteColor('blue');
src/renderers/shared/reconciler/__tests__/ReactMultiChildReconcile-test.js
+20 -8
@@ -15,7 +15,6 @@ require('mock-modules');
15
16 var React = require('React');
17 var ReactInstanceMap = require('ReactInstanceMap');
18 -var ReactTestUtils = require('ReactTestUtils');
18 var ReactMount = require('ReactMount');
19
20 var mapObject = require('mapObject');
@@ -212,15 +211,20 @@ function verifyDomOrderingAccurate(parentInstance, statusDisplays) {
211 */
212 function testPropsSequence(sequence) {
213 var i;
215 - var parentInstance = ReactTestUtils.renderIntoDocument(
216 - <FriendsStatusDisplay {...sequence[0]} />
214 + var container = document.createElement('div');
215 + var parentInstance = React.render(
216 + <FriendsStatusDisplay {...sequence[0]} />,
217 + container
218 );
219 var statusDisplays = parentInstance.getStatusDisplays();
220 var lastInternalStates = getInteralStateByUserName(statusDisplays);
221 verifyStatuses(statusDisplays, sequence[0]);
222
223 for (i = 1; i < sequence.length; i++) {
223 - parentInstance.replaceProps(sequence[i]);
224 + React.render(
225 + <FriendsStatusDisplay {...sequence[i]} />,
226 + container
227 + );
228 statusDisplays = parentInstance.getStatusDisplays();
229 verifyStatuses(statusDisplays, sequence[i]);
230 verifyStatesPreserved(lastInternalStates, statusDisplays);
@@ -243,19 +247,27 @@ describe('ReactMultiChildReconcile', function() {
247 },
248 };
249
246 - var parentInstance = ReactTestUtils.renderIntoDocument(
247 - <FriendsStatusDisplay {...props} />
250 + var container = document.createElement('div');
251 + var parentInstance = React.render(
252 + <FriendsStatusDisplay {...props} />,
253 + container
254 );
255 var statusDisplays = parentInstance.getStatusDisplays();
256 var startingInternalState = statusDisplays.jcw.getInternalState();
257
258 // Now remove the child.
253 - parentInstance.replaceProps({usernameToStatus: {} });
259 + React.render(
260 + <FriendsStatusDisplay />,
261 + container
262 + );
263 statusDisplays = parentInstance.getStatusDisplays();
264 expect(statusDisplays.jcw).toBeFalsy();
265
266 // Now reset the props that cause there to be a child
258 - parentInstance.replaceProps(props);
267 + React.render(
268 + <FriendsStatusDisplay {...props} />,
269 + container
270 + );
271 statusDisplays = parentInstance.getStatusDisplays();
272 expect(statusDisplays.jcw).toBeTruthy();
273 expect(statusDisplays.jcw.getInternalState())