mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Update warn message and move it to the error-catching block
This commit is contained in:
@@ -194,6 +194,13 @@ var ReactCompositeComponentMixin = {
|
||||
'expected to return a value.',
|
||||
(this.getName() || 'A component')
|
||||
);
|
||||
warning(
|
||||
typeof inst.componentDidUnmount !== 'function',
|
||||
'%s has a method called ' +
|
||||
'componentDidUnmount(). But there is no such lifecycle method. ' +
|
||||
'Did you mean componentWillUnmount()?',
|
||||
this.getName() || 'A component'
|
||||
);
|
||||
warning(
|
||||
typeof inst.componentWillRecieveProps !== 'function',
|
||||
'%s has a method called ' +
|
||||
@@ -257,14 +264,6 @@ var ReactCompositeComponentMixin = {
|
||||
if (inst.componentWillUnmount) {
|
||||
inst.componentWillUnmount();
|
||||
}
|
||||
if (__DEV__) {
|
||||
warning(
|
||||
typeof inst.componentDidUnmount !== 'function',
|
||||
'componentDidUnmount was defined on %s. But there is no such ' +
|
||||
'lifecycle method. Use componentWillUnmount instead.',
|
||||
this.getName() || 'ReactCompositeComponent'
|
||||
);
|
||||
}
|
||||
|
||||
ReactReconciler.unmountComponent(this._renderedComponent);
|
||||
this._renderedComponent = null;
|
||||
|
||||
@@ -552,10 +552,7 @@ describe('ReactCompositeComponent', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when defined method componentDidUnmount', function() {
|
||||
var container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
|
||||
it('should warn when componentDidUnmount method is defined', function() {
|
||||
var Component = React.createClass({
|
||||
componentDidUnmount: function() {
|
||||
},
|
||||
@@ -565,17 +562,13 @@ describe('ReactCompositeComponent', function() {
|
||||
},
|
||||
});
|
||||
|
||||
var instance = <Component />;
|
||||
|
||||
instance = React.render(instance, container);
|
||||
expect(console.error.calls.length).toBe(0);
|
||||
|
||||
React.unmountComponentAtNode(container);
|
||||
ReactTestUtils.renderIntoDocument(<Component />);
|
||||
|
||||
expect(console.error.calls.length).toBe(1);
|
||||
expect(console.error.argsForCall[0][0]).toBe(
|
||||
'Warning: componentDidUnmount was defined on Component. But there is no such ' +
|
||||
'lifecycle method. Use componentWillUnmount instead.'
|
||||
'Warning: Component has a method called ' +
|
||||
'componentDidUnmount(). But there is no such lifecycle method. ' +
|
||||
'Did you mean componentWillUnmount()?'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user