diff --git a/src/renderers/shared/reconciler/ReactCompositeComponent.js b/src/renderers/shared/reconciler/ReactCompositeComponent.js
index ad2c53aeb7..9a8a332443 100644
--- a/src/renderers/shared/reconciler/ReactCompositeComponent.js
+++ b/src/renderers/shared/reconciler/ReactCompositeComponent.js
@@ -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;
diff --git a/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js b/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js
index cc70e59ba5..51d1a739b6 100644
--- a/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js
+++ b/src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js
@@ -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 = ;
-
- instance = React.render(instance, container);
- expect(console.error.calls.length).toBe(0);
-
- React.unmountComponentAtNode(container);
+ ReactTestUtils.renderIntoDocument();
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()?'
);
});