Permalink
Browse files

Replace createClass with external react-create-class dependency

Warns when using React.createClass for the first time.

Usages of createClass in tests have been converted to plain JavaScript
classes. Tests that rely on replaceState or isMounted use
updater.enqueueReplaceState and updater.isMounted.
  • Loading branch information...
acdlite committed Mar 21, 2017
1 parent 60a7955 commit d9a4fa4f51c6da895e1655f32255cf72c0fe620e
Showing with 628 additions and 3,732 deletions.
  1. +4 −4 mocks/ReactElementTestChild.js
  2. +8 −13 mocks/ReactMockedComponentTestComponent.js
  3. +1 −0 package.json
  4. +0 −145 src/addons/__tests__/ReactComponentWithPureRenderMixin-test.js
  5. +0 −46 src/addons/link/__tests__/LinkedStateMixin-test.js
  6. +0 −164 src/addons/link/__tests__/ReactLinkPropTypes-test.js
  7. +0 −330 src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
  8. +0 −321 src/addons/transitions/__tests__/ReactTransitionGroup-test.js
  9. +80 −87 src/isomorphic/classic/__tests__/ReactContextValidator-test.js
  10. +15 −860 src/isomorphic/classic/class/ReactClass.js
  11. +0 −166 src/isomorphic/classic/class/__tests__/ReactBind-test.js
  12. +0 −233 src/isomorphic/classic/class/__tests__/ReactBindOptout-test.js
  13. +20 −0 src/isomorphic/classic/class/__tests__/ReactClass-test.js
  14. +0 −545 src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js
  15. +69 −125 src/isomorphic/classic/element/__tests__/ReactElement-test.js
  16. +88 −90 src/isomorphic/classic/element/__tests__/ReactElementClone-test.js
  17. +81 −104 src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js
  18. +6 −6 src/renderers/dom/client/__tests__/ReactMount-test.js
  19. +5 −3 src/renderers/dom/client/eventPlugins/__tests__/BeforeInputEventPlugin-test.js
  20. +0 −26 src/renderers/dom/server/__tests__/ReactServerRendering-test.js
  21. +26 −30 src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
  22. +10 −10 src/renderers/shared/__tests__/ReactPerf-test.js
  23. +6 −8 src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
  24. +9 −2 src/renderers/shared/hooks/__tests__/ReactComponentTreeHook-test.js
  25. +72 −61 src/renderers/shared/stack/reconciler/__tests__/ReactComponentLifeCycle-test.js
  26. +19 −77 src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponent-test.js
  27. +34 −32 src/renderers/shared/stack/reconciler/__tests__/ReactCompositeComponentState-test.js
  28. +25 −25 src/renderers/shared/stack/reconciler/__tests__/ReactMultiChild-test.js
  29. +0 −152 src/renderers/shared/stack/reconciler/__tests__/ReactStateSetters-test.js
  30. +21 −57 src/renderers/shared/stack/reconciler/__tests__/ReactUpdates-test.js
  31. +5 −5 src/test/__tests__/ReactTestUtils-test.js
  32. +24 −5 yarn.lock
@@ -13,10 +13,10 @@
var React = require('React');
-var Child = React.createClass({
- render: function() {
+class Child extends React.Component {
+ render() {
return React.createElement('div');
- },
-});
+ }
+}
module.exports = Child;
@@ -13,23 +13,18 @@
var React = require('React');
-var ReactMockedComponentTestComponent = React.createClass({
- getDefaultProps: function() {
- return {bar: 'baz'};
- },
+class ReactMockedComponentTestComponent extends React.Component {
+ state = {foo: 'bar'};
- getInitialState: function() {
- return {foo: 'bar'};
- },
-
- hasCustomMethod: function() {
+ hasCustomMethod() {
return true;
- },
+ }
- render: function() {
+ render() {
return <span />;
- },
+ }
-});
+}
+ReactMockedComponentTestComponent.defaultProps = {bar: 'baz'};
module.exports = ReactMockedComponentTestComponent;
View
@@ -69,6 +69,7 @@
"merge-stream": "^1.0.0",
"object-assign": "^4.1.1",
"platform": "^1.1.0",
+ "react-create-class": "15.5.0-alpha.2",
"run-sequence": "^1.1.4",
"through2": "^2.0.0",
"tmp": "~0.0.28",
@@ -1,145 +0,0 @@
-/**
- * Copyright 2015-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 ReactComponentWithPureRenderMixin;
-var ReactTestUtils;
-
-describe('ReactComponentWithPureRenderMixin', () => {
-
- beforeEach(() => {
- React = require('React');
- ReactComponentWithPureRenderMixin =
- require('ReactComponentWithPureRenderMixin');
- ReactTestUtils = require('ReactTestUtils');
- });
-
- it('provides a default shouldComponentUpdate implementation', () => {
- var renderCalls = 0;
- class PlasticWrap extends React.Component {
- constructor(props, context) {
- super(props, context);
- this.state = {
- color: 'green',
- };
- }
-
- render() {
- return (
- <Apple
- color={this.state.color}
- ref="apple"
- />
- );
- }
- }
-
- var Apple = React.createClass({
- mixins: [ReactComponentWithPureRenderMixin],
-
- getInitialState: function() {
- return {
- cut: false,
- slices: 1,
- };
- },
-
- cut: function() {
- this.setState({
- cut: true,
- slices: 10,
- });
- },
-
- eatSlice: function() {
- this.setState({
- slices: this.state.slices - 1,
- });
- },
-
- render: function() {
- renderCalls++;
- return <div />;
- },
- });
-
- var instance = ReactTestUtils.renderIntoDocument(<PlasticWrap />);
- expect(renderCalls).toBe(1);
-
- // Do not re-render based on props
- instance.setState({color: 'green'});
- expect(renderCalls).toBe(1);
-
- // Re-render based on props
- instance.setState({color: 'red'});
- expect(renderCalls).toBe(2);
-
- // Re-render base on state
- instance.refs.apple.cut();
- expect(renderCalls).toBe(3);
-
- // No re-render based on state
- instance.refs.apple.cut();
- expect(renderCalls).toBe(3);
-
- // Re-render based on state again
- instance.refs.apple.eatSlice();
- expect(renderCalls).toBe(4);
- });
-
- it('does not do a deep comparison', () => {
- function getInitialState() {
- return {
- foo: [1, 2, 3],
- bar: {a: 4, b: 5, c: 6},
- };
- }
-
- var renderCalls = 0;
- var initialSettings = getInitialState();
-
- var Component = React.createClass({
- mixins: [ReactComponentWithPureRenderMixin],
-
- getInitialState: function() {
- return initialSettings;
- },
-
- render: function() {
- renderCalls++;
- return <div />;
- },
- });
-
- var instance = ReactTestUtils.renderIntoDocument(<Component />);
- expect(renderCalls).toBe(1);
-
- // Do not re-render if state is equal
- var settings = {
- foo: initialSettings.foo,
- bar: initialSettings.bar,
- };
- instance.setState(settings);
- expect(renderCalls).toBe(1);
-
- // Re-render because one field changed
- initialSettings.foo = [1, 2, 3];
- instance.setState(initialSettings);
- expect(renderCalls).toBe(2);
-
- // Re-render because the object changed
- instance.setState(getInitialState());
- expect(renderCalls).toBe(3);
- });
-
-});
@@ -1,46 +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';
-
-
-describe('LinkedStateMixin', () => {
- var LinkedStateMixin;
- var React;
- var ReactTestUtils;
-
- beforeEach(() => {
- LinkedStateMixin = require('LinkedStateMixin');
- React = require('React');
- ReactTestUtils = require('ReactTestUtils');
- });
-
- it('should create a ReactLink for state', () => {
- var Component = React.createClass({
- mixins: [LinkedStateMixin],
-
- getInitialState: function() {
- return {value: 'initial value'};
- },
-
- render: function() {
- return <span>value is {this.state.value}</span>;
- },
- });
- var component = ReactTestUtils.renderIntoDocument(<Component />);
- var link = component.linkState('value');
- expect(component.state.value).toBe('initial value');
- expect(link.value).toBe('initial value');
- link.requestChange('new value');
- expect(component.state.value).toBe('new value');
- expect(component.linkState('value').value).toBe('new value');
- });
-});
Oops, something went wrong.

0 comments on commit d9a4fa4

Please sign in to comment.