mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
@@ -257,6 +257,14 @@ 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,6 +552,33 @@ describe('ReactCompositeComponent', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when defined method componentDidUnmount', function() {
|
||||
var container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
|
||||
var Component = React.createClass({
|
||||
componentDidUnmount: function() {
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return <div />;
|
||||
},
|
||||
});
|
||||
|
||||
var instance = <Component />;
|
||||
|
||||
instance = React.render(instance, container);
|
||||
expect(console.error.calls.length).toBe(0);
|
||||
|
||||
React.unmountComponentAtNode(container);
|
||||
|
||||
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.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should pass context to children when not owner', function() {
|
||||
var Parent = React.createClass({
|
||||
render: function() {
|
||||
|
||||
Reference in New Issue
Block a user