Merge pull request #294 from clayallsopp/better_update_msg

More helpful message if you update an unrendered component
This commit is contained in:
Paul O’Shannessy
2013-09-05 11:54:07 -07:00
2 changed files with 25 additions and 0 deletions
+4
View File
@@ -278,6 +278,10 @@ var ReactComponent = {
'`render` method to pass the correct value as props to the component ' +
'where it is created.'
);
invariant(
this.isMounted(),
'replaceProps(...): Can only update a mounted component.'
);
this._pendingProps = props;
ReactUpdates.enqueueUpdate(this, callback);
},
@@ -408,6 +408,27 @@ describe('ReactComponentLifeCycle', function() {
.toThrow();
});
it('should throw when calling setProps() on an unmounted component',
function() {
var PropsToUpdate = React.createClass({
render: function() {
return (
<input
value={this.props.value}
ref="theSimpleComponent">
</input>
);
}
});
var instance = <PropsToUpdate value="hello" />;
expect(function() {
instance.setProps({value: "goodbye"});
}).toThrow(
'Invariant Violation: replaceProps(...): Can only update a ' +
'mounted component.'
);
});
it('should allow state updates in componentDidMount', function() {
/**
* calls setState in an componentDidMount.