@samitouri / QOS-React-2 / commits / 2568933ca3

Update warn message and move it to the error-catching block

oluckyman committed Jun 22, 2015 at 23:52 UTC 2568933ca3f73bd2e491a755128f0c803f5e4883
2 files changed +12 -20
src/renderers/shared/reconciler/ReactCompositeComponent.js
+7 -8
@@ -194,6 +194,13 @@ var ReactCompositeComponentMixin = {
194 'expected to return a value.',
195 (this.getName() || 'A component')
196 );
197 + warning(
198 + typeof inst.componentDidUnmount !== 'function',
199 + '%s has a method called ' +
200 + 'componentDidUnmount(). But there is no such lifecycle method. ' +
201 + 'Did you mean componentWillUnmount()?',
202 + this.getName() || 'A component'
203 + );
204 warning(
205 typeof inst.componentWillRecieveProps !== 'function',
206 '%s has a method called ' +
@@ -257,14 +264,6 @@ var ReactCompositeComponentMixin = {
264 if (inst.componentWillUnmount) {
265 inst.componentWillUnmount();
266 }
260 - if (__DEV__) {
261 - warning(
262 - typeof inst.componentDidUnmount !== 'function',
263 - 'componentDidUnmount was defined on %s. But there is no such ' +
264 - 'lifecycle method. Use componentWillUnmount instead.',
265 - this.getName() || 'ReactCompositeComponent'
266 - );
267 - }
267
268 ReactReconciler.unmountComponent(this._renderedComponent);
269 this._renderedComponent = null;
src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js
+5 -12
@@ -552,10 +552,7 @@ describe('ReactCompositeComponent', function() {
552 );
553 });
554
555 - it('should warn when defined method componentDidUnmount', function() {
556 - var container = document.createElement('div');
557 - document.body.appendChild(container);
558 -
555 + it('should warn when componentDidUnmount method is defined', function() {
556 var Component = React.createClass({
557 componentDidUnmount: function() {
558 },
@@ -565,17 +562,13 @@ describe('ReactCompositeComponent', function() {
562 },
563 });
564
568 - var instance = <Component />;
569 -
570 - instance = React.render(instance, container);
571 - expect(console.error.calls.length).toBe(0);
572 -
573 - React.unmountComponentAtNode(container);
565 + ReactTestUtils.renderIntoDocument(<Component />);
566
567 expect(console.error.calls.length).toBe(1);
568 expect(console.error.argsForCall[0][0]).toBe(
577 - 'Warning: componentDidUnmount was defined on Component. But there is no such ' +
578 - 'lifecycle method. Use componentWillUnmount instead.'
569 + 'Warning: Component has a method called ' +
570 + 'componentDidUnmount(). But there is no such lifecycle method. ' +
571 + 'Did you mean componentWillUnmount()?'
572 );
573 });
574