Removed most uses of setProps in unit tests

Picked from 721fe73541.
This commit is contained in:
Ben Alpert
2015-07-03 10:20:56 +02:00
parent 4eb889b72e
commit 2b68ea21ee
5 changed files with 39 additions and 31 deletions
@@ -121,9 +121,9 @@ describe('ReactContextValidator', function() {
},
});
var instance = <Parent foo="abc" />;
instance = ReactTestUtils.renderIntoDocument(instance);
instance.replaceProps({foo: 'def'});
var container = document.createElement('div');
React.render(<Parent foo="abc" />, container);
React.render(<Parent foo="def" />, container);
expect(actualComponentWillReceiveProps).toEqual({foo: 'def'});
expect(actualShouldComponentUpdate).toEqual({foo: 'def'});
expect(actualComponentWillUpdate).toEqual({foo: 'def'});
@@ -512,24 +512,18 @@ describe('ReactComponentLifeCycle', function() {
},
});
var instance = ReactTestUtils.renderIntoDocument(
<Component text="uno" tooltipText="one" />
var container = document.createElement('div');
React.render(
<Component text="uno" tooltipText="one" />,
container
);
// Since `instance` is a root component, we can set its props. This also
// makes Tooltip rerender the tooltip component, which shouldn't throw.
instance.setProps({text: 'dos', tooltipText: 'two'});
});
it('should not allow setProps() called on an unmounted element',
function() {
var PropsToUpdate = React.createClass({
render: function() {
return <div className={this.props.value} ref="theSimpleComponent" />;
},
});
var instance = <PropsToUpdate value="hello" />;
expect(instance.setProps).not.toBeDefined();
React.render(
<Component text="dos" tooltipText="two" />,
container
);
});
it('should allow state updates in componentDidMount', function() {
@@ -595,7 +589,7 @@ describe('ReactComponentLifeCycle', function() {
var container = document.createElement('div');
log = [];
var instance = React.render(<Outer x={17} />, container);
React.render(<Outer x={17} />, container);
expect(log).toEqual([
'outer componentWillMount',
'inner componentWillMount',
@@ -604,7 +598,7 @@ describe('ReactComponentLifeCycle', function() {
]);
log = [];
instance.setProps({x: 42});
React.render(<Outer x={42} />, container);
expect(log).toEqual([
'outer componentWillReceiveProps',
'outer shouldComponentUpdate',
@@ -935,7 +935,8 @@ describe('ReactCompositeComponent', function() {
},
});
var comp = ReactTestUtils.renderIntoDocument(<Component flipped={false} />);
var container = document.createElement('div');
var comp = React.render(<Component flipped={false} />, container);
expect(React.findDOMNode(comp.refs.static0).textContent).toBe('A');
expect(React.findDOMNode(comp.refs.static1).textContent).toBe('B');
@@ -946,7 +947,7 @@ describe('ReactCompositeComponent', function() {
// When flipping the order, the refs should update even though the actual
// contents do not
comp.setProps({flipped: true});
React.render(<Component flipped={true} />, container);
expect(React.findDOMNode(comp.refs.static0).textContent).toBe('B');
expect(React.findDOMNode(comp.refs.static1).textContent).toBe('A');
@@ -138,8 +138,9 @@ describe('ReactCompositeComponent-state', function() {
this.peekAtState('initial-callback');
}
);
instance.setProps(
{nextColor: 'green'},
React.render(
<TestComponent stateListener={stateListener} nextColor="green" />,
container,
instance.peekAtCallback('setProps')
);
instance.setFavoriteColor('blue');
@@ -15,7 +15,6 @@ require('mock-modules');
var React = require('React');
var ReactInstanceMap = require('ReactInstanceMap');
var ReactTestUtils = require('ReactTestUtils');
var ReactMount = require('ReactMount');
var mapObject = require('mapObject');
@@ -212,15 +211,20 @@ function verifyDomOrderingAccurate(parentInstance, statusDisplays) {
*/
function testPropsSequence(sequence) {
var i;
var parentInstance = ReactTestUtils.renderIntoDocument(
<FriendsStatusDisplay {...sequence[0]} />
var container = document.createElement('div');
var parentInstance = React.render(
<FriendsStatusDisplay {...sequence[0]} />,
container
);
var statusDisplays = parentInstance.getStatusDisplays();
var lastInternalStates = getInteralStateByUserName(statusDisplays);
verifyStatuses(statusDisplays, sequence[0]);
for (i = 1; i < sequence.length; i++) {
parentInstance.replaceProps(sequence[i]);
React.render(
<FriendsStatusDisplay {...sequence[i]} />,
container
);
statusDisplays = parentInstance.getStatusDisplays();
verifyStatuses(statusDisplays, sequence[i]);
verifyStatesPreserved(lastInternalStates, statusDisplays);
@@ -243,19 +247,27 @@ describe('ReactMultiChildReconcile', function() {
},
};
var parentInstance = ReactTestUtils.renderIntoDocument(
<FriendsStatusDisplay {...props} />
var container = document.createElement('div');
var parentInstance = React.render(
<FriendsStatusDisplay {...props} />,
container
);
var statusDisplays = parentInstance.getStatusDisplays();
var startingInternalState = statusDisplays.jcw.getInternalState();
// Now remove the child.
parentInstance.replaceProps({usernameToStatus: {} });
React.render(
<FriendsStatusDisplay />,
container
);
statusDisplays = parentInstance.getStatusDisplays();
expect(statusDisplays.jcw).toBeFalsy();
// Now reset the props that cause there to be a child
parentInstance.replaceProps(props);
React.render(
<FriendsStatusDisplay {...props} />,
container
);
statusDisplays = parentInstance.getStatusDisplays();
expect(statusDisplays.jcw).toBeTruthy();
expect(statusDisplays.jcw.getInternalState())