diff --git a/src/browser/__tests__/ReactDOM-test.js b/src/browser/__tests__/ReactDOM-test.js index 229ccda1625..c47ef01f69b 100644 --- a/src/browser/__tests__/ReactDOM-test.js +++ b/src/browser/__tests__/ReactDOM-test.js @@ -108,10 +108,6 @@ describe('ReactDOM', function() { expect(dog.className).toBe('bigdog'); }); - it('should be a valid class', function() { - expect(React.isValidClass(ReactDOM.div)).toBe(false); - }); - it('allow React.DOM factories to be called without warnings', function() { spyOn(console, 'warn'); var element = React.DOM.div(); diff --git a/src/browser/ui/React.js b/src/browser/ui/React.js index 7b600cb9093..4b296ff8a07 100644 --- a/src/browser/ui/React.js +++ b/src/browser/ui/React.js @@ -77,7 +77,7 @@ var React = { renderToString: ReactServerRendering.renderToString, renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup, unmountComponentAtNode: ReactMount.unmountComponentAtNode, - isValidClass: ReactLegacyElement.isValidFactory, + isValidClass: ReactLegacyElement.isValidClass, isValidElement: ReactElement.isValidElement, withContext: ReactContext.withContext, diff --git a/src/core/ReactLegacyElement.js b/src/core/ReactLegacyElement.js index 909fe1aa77f..67b9c7fb6bb 100644 --- a/src/core/ReactLegacyElement.js +++ b/src/core/ReactLegacyElement.js @@ -227,6 +227,17 @@ ReactLegacyElementFactory.isValidFactory = function(factory) { factory.isReactLegacyFactory === LEGACY_MARKER; }; +ReactLegacyElementFactory.isValidClass = function(factory) { + if (__DEV__) { + warning( + false, + 'isValidClass is deprecated and will be removed in a future release. ' + + 'Use a more specific validator instead.' + ); + } + return ReactLegacyElementFactory.isValidFactory(factory); +}; + ReactLegacyElementFactory._isLegacyCallWarningEnabled = true; module.exports = ReactLegacyElementFactory; diff --git a/src/core/__tests__/ReactCompositeComponent-test.js b/src/core/__tests__/ReactCompositeComponent-test.js index 6cf8bbd9451..bfe8e423711 100644 --- a/src/core/__tests__/ReactCompositeComponent-test.js +++ b/src/core/__tests__/ReactCompositeComponent-test.js @@ -878,7 +878,10 @@ describe('ReactCompositeComponent', function() { expect(ReactMount.purgeID.callCount).toBe(4); }); - it('should detect valid CompositeComponent classes', function() { + it('should warn but detect valid CompositeComponent classes', function() { + var warn = console.warn; + console.warn = mocks.getMockFunction(); + var Component = React.createClass({ render: function() { return
; @@ -886,9 +889,17 @@ describe('ReactCompositeComponent', function() { }); expect(React.isValidClass(Component)).toBe(true); + + expect(console.warn.mock.calls.length).toBe(1); + expect(console.warn.mock.calls[0][0]).toContain( + 'isValidClass is deprecated and will be removed in a future release' + ); }); - it('should detect invalid CompositeComponent classes', function() { + it('should warn but detect invalid CompositeComponent classes', function() { + var warn = console.warn; + console.warn = mocks.getMockFunction(); + var FnComponent = function() { return false; }; @@ -903,6 +914,13 @@ describe('ReactCompositeComponent', function() { expect(React.isValidClass(FnComponent)).toBe(false); expect(React.isValidClass(NullComponent)).toBe(false); expect(React.isValidClass(TrickFnComponent)).toBe(false); + + expect(console.warn.mock.calls.length).toBe(3); + console.warn.mock.calls.forEach(function(call) { + expect(call[0]).toContain( + 'isValidClass is deprecated and will be removed in a future release' + ); + }); }); it('should warn when shouldComponentUpdate() returns undefined', function() {