diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js index f10de36d2e98f..a522d2c65ace2 100644 --- a/src/isomorphic/React.js +++ b/src/isomorphic/React.js @@ -12,15 +12,16 @@ 'use strict'; var ReactChildren = require('ReactChildren'); +var ReactClass = require('ReactClass'); var ReactComponent = require('ReactComponent'); var ReactPureComponent = require('ReactPureComponent'); -var ReactClass = require('ReactClass'); var ReactDOMFactories = require('ReactDOMFactories'); var ReactElement = require('ReactElement'); var ReactPropTypes = require('ReactPropTypes'); var ReactVersion = require('ReactVersion'); var onlyChild = require('onlyChild'); +var warning = require('warning'); var createElement = ReactElement.createElement; var createFactory = ReactElement.createFactory; @@ -55,16 +56,6 @@ if (__DEV__) { warnedForSpread = true; return Object.assign.apply(null, arguments); }; - - createMixin = function(mixin) { - lowPriorityWarning( - warnedForCreateMixin, - 'React.createMixin is deprecated and should not be used. You ' + - 'can use this mixin directly instead.', - ); - warnedForCreateMixin = true; - return mixin; - }; } var React = { @@ -102,8 +93,9 @@ var React = { __spread: __spread, }; -// TODO: Fix tests so that this deprecation warning doesn't cause failures. if (__DEV__) { + let warnedForCreateMixin = false; + let warnedForCreateClass = false; if (canDefineProperty) { Object.defineProperty(React, 'PropTypes', { get() { @@ -127,7 +119,7 @@ if (__DEV__) { 'drop-in replacement.', ); didWarnPropTypesDeprecated = true; - return ReactPropTypes; + return ReactClass.createClass; }, }); } diff --git a/src/isomorphic/classic/class/__tests__/ReactClass-test.js b/src/isomorphic/classic/class/__tests__/ReactClass-test.js deleted file mode 100644 index 17fa24e6776bc..0000000000000 --- a/src/isomorphic/classic/class/__tests__/ReactClass-test.js +++ /dev/null @@ -1,372 +0,0 @@ -/** - * Copyright 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @emails react-core - */ - -'use strict'; - -var React; -var ReactDOM; -var ReactTestUtils; -var PropTypes; - -describe('ReactClass-spec', () => { - beforeEach(() => { - React = require('React'); - ReactDOM = require('ReactDOM'); - ReactTestUtils = require('ReactTestUtils'); - PropTypes = require('prop-types'); - }); - - it('should warn on first call to React.createClass', () => { - spyOn(console, 'error'); - const spec = { - displayName: 'MyComponent', - render() { - return
; - }, - }; - React.createClass(spec); - React.createClass(spec); - expect(console.error.calls.count()).toEqual(1); - expect(console.error.calls.count()).toEqual(1); - expect(console.error.calls.argsFor(0)[0]).toBe( - 'Warning: MyComponent: React.createClass is deprecated and will be removed in ' + - "version 16. Use plain JavaScript classes instead. If you're not yet " + - 'ready to migrate, create-react-class is available on npm as a ' + - 'drop-in replacement.', - ); - console.error.calls.reset(); - }); - - it('should throw when `render` is not specified', () => { - expect(function() { - React.createClass({}); - }).toThrowError( - 'createClass(...): Class specification must implement a `render` method.', - ); - }); - - it('should copy `displayName` onto the Constructor', () => { - var TestComponent = React.createClass({ - render: function() { - return ; - }, - }); - - expect(TestComponent.displayName).toBe('TestComponent'); - }); - - it('should copy prop types onto the Constructor', () => { - var propValidator = jest.fn(); - var TestComponent = React.createClass({ - propTypes: { - value: propValidator, - }, - render: function() { - return ; - }, - }); - - expect(TestComponent.propTypes).toBeDefined(); - expect(TestComponent.propTypes.value).toBe(propValidator); - }); - - it('should warn on invalid prop types', () => { - spyOn(console, 'error'); - React.createClass({ - displayName: 'Component', - propTypes: { - prop: null, - }, - render: function() { - return {this.props.prop}; - }, - }); - expect(console.error.calls.count()).toBe(1); - expect(console.error.calls.argsFor(0)[0]).toBe( - 'Warning: Component: prop type `prop` is invalid; ' + - 'it must be a function, usually from React.PropTypes.', - ); - }); - - it('should warn on invalid context types', () => { - spyOn(console, 'error'); - React.createClass({ - displayName: 'Component', - contextTypes: { - prop: null, - }, - render: function() { - return {this.props.prop}; - }, - }); - expect(console.error.calls.count()).toBe(1); - expect(console.error.calls.argsFor(0)[0]).toBe( - 'Warning: Component: context type `prop` is invalid; ' + - 'it must be a function, usually from React.PropTypes.', - ); - }); - - it('should throw on invalid child context types', () => { - spyOn(console, 'error'); - React.createClass({ - displayName: 'Component', - childContextTypes: { - prop: null, - }, - render: function() { - return {this.props.prop}; - }, - }); - expect(console.error.calls.count()).toBe(1); - expect(console.error.calls.argsFor(0)[0]).toBe( - 'Warning: Component: child context type `prop` is invalid; ' + - 'it must be a function, usually from React.PropTypes.', - ); - }); - - it('should warn when mispelling shouldComponentUpdate', () => { - spyOn(console, 'error'); - - React.createClass({ - componentShouldUpdate: function() { - return false; - }, - render: function() { - return ; - }, - }); - expect(console.error.calls.count()).toBe(1); - expect(console.error.calls.argsFor(0)[0]).toBe( - 'Warning: A component has a method called componentShouldUpdate(). Did you ' + - 'mean shouldComponentUpdate()? The name is phrased as a question ' + - 'because the function is expected to return a value.', - ); - - React.createClass({ - displayName: 'NamedComponent', - componentShouldUpdate: function() { - return false; - }, - render: function() { - return ; - }, - }); - expect(console.error.calls.count()).toBe(2); - expect(console.error.calls.argsFor(1)[0]).toBe( - 'Warning: NamedComponent has a method called componentShouldUpdate(). Did you ' + - 'mean shouldComponentUpdate()? The name is phrased as a question ' + - 'because the function is expected to return a value.', - ); - }); - - it('should warn when mispelling componentWillReceiveProps', () => { - spyOn(console, 'error'); - React.createClass({ - componentWillRecieveProps: function() { - return false; - }, - render: function() { - return ; - }, - }); - expect(console.error.calls.count()).toBe(1); - expect(console.error.calls.argsFor(0)[0]).toBe( - 'Warning: A component has a method called componentWillRecieveProps(). Did you ' + - 'mean componentWillReceiveProps()?', - ); - }); - - it('should throw if a reserved property is in statics', () => { - expect(function() { - React.createClass({ - statics: { - getDefaultProps: function() { - return { - foo: 0, - }; - }, - }, - - render: function() { - return ; - }, - }); - }).toThrowError( - 'ReactClass: You are attempting to define a reserved property, ' + - '`getDefaultProps`, that shouldn\'t be on the "statics" key. Define ' + - 'it as an instance property instead; it will still be accessible on ' + - 'the constructor.', - ); - }); - - // TODO: Consider actually moving these to statics or drop this unit test. - - xit('should warn when using deprecated non-static spec keys', () => { - spyOn(console, 'error'); - React.createClass({ - mixins: [{}], - propTypes: { - foo: PropTypes.string, - }, - contextTypes: { - foo: PropTypes.string, - }, - childContextTypes: { - foo: PropTypes.string, - }, - render: function() { - return ; - }, - }); - expect(console.error.calls.count()).toBe(4); - expect(console.error.calls.argsFor(0)[0]).toBe( - 'createClass(...): `mixins` is now a static property and should ' + - 'be defined inside "statics".', - ); - expect(console.error.calls.argsFor(1)[0]).toBe( - 'createClass(...): `propTypes` is now a static property and should ' + - 'be defined inside "statics".', - ); - expect(console.error.calls.argsFor(2)[0]).toBe( - 'createClass(...): `contextTypes` is now a static property and ' + - 'should be defined inside "statics".', - ); - expect(console.error.calls.argsFor(3)[0]).toBe( - 'createClass(...): `childContextTypes` is now a static property and ' + - 'should be defined inside "statics".', - ); - }); - - it('should support statics', () => { - var Component = React.createClass({ - statics: { - abc: 'def', - def: 0, - ghi: null, - jkl: 'mno', - pqr: function() { - return this; - }, - }, - - render: function() { - return ; - }, - }); - var instance =