Skip to content

Commit

Permalink
Use createClass from react-compat instead of React.createClass
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 9, 2017
1 parent 1f74f7b commit fe21976
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
26 changes: 13 additions & 13 deletions test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import sinon from 'sinon';
import { batchedUpdates } from '../src/react-compat';
import { batchedUpdates, createClass } from '../src/react-compat';

import {
describeWithDOM,
Expand All @@ -24,7 +24,7 @@ import { REACT013, REACT014, REACT15 } from '../src/version';
describeWithDOM('mount', () => {
describe('context', () => {
it('can pass in context', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
Expand All @@ -39,15 +39,15 @@ describeWithDOM('mount', () => {
});

it('can pass context to the child of mounted component', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
},
});
const ComplexComponent = React.createClass({
const ComplexComponent = createClass({
render() {
return <div><SimpleComponent /></div>;
},
Expand All @@ -62,7 +62,7 @@ describeWithDOM('mount', () => {
});

it('should not throw if context is passed in but contextTypes is missing', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
render() {
return <div>{this.context.name}</div>;
},
Expand All @@ -73,7 +73,7 @@ describeWithDOM('mount', () => {
});

it('is instrospectable through context API', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
Expand Down Expand Up @@ -1097,7 +1097,7 @@ describeWithDOM('mount', () => {

describe('.setContext(newContext)', () => {
it('should set context for a component multiple times', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
Expand All @@ -1116,7 +1116,7 @@ describeWithDOM('mount', () => {
});

it('should throw if it is called when shallow didn’t include context', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
Expand Down Expand Up @@ -1467,7 +1467,7 @@ describeWithDOM('mount', () => {
const emptyRenderValues = generateEmptyRenderData();

itWithData(emptyRenderValues, 'when a React class component returns: ', (data) => {
const Foo = React.createClass({
const Foo = createClass({
render() {
return data.value;
},
Expand Down Expand Up @@ -3268,9 +3268,9 @@ describeWithDOM('mount', () => {
});
});

describe('React.createClass', () => {
describe('createClass', () => {
it('should return the name of the node', () => {
const Foo = React.createClass({
const Foo = createClass({
displayName: 'CustomWrapper',
render() {
return <div />;
Expand Down Expand Up @@ -3304,9 +3304,9 @@ describeWithDOM('mount', () => {
});
});

describe('React.createClass', () => {
describe('createClass', () => {
it('should return the name of the node', () => {
const Foo = React.createClass({
const Foo = createClass({
render() {
return <div />;
},
Expand Down
23 changes: 12 additions & 11 deletions test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import { expect } from 'chai';
import sinon from 'sinon';

import { createClass } from '../src/react-compat';
import { shallow, render, ShallowWrapper } from '../src/';
import { describeIf, itIf, itWithData, generateEmptyRenderData } from './_helpers';
import { ITERATOR_SYMBOL, withSetStateAllowed } from '../src/Utils';
Expand All @@ -11,7 +12,7 @@ import { REACT013, REACT014, REACT15 } from '../src/version';
describe('shallow', () => {
describe('context', () => {
it('can pass in context', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
Expand All @@ -26,7 +27,7 @@ describe('shallow', () => {
});

it('should not throw if context is passed in but contextTypes is missing', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
render() {
return <div>{this.context.name}</div>;
},
Expand All @@ -37,7 +38,7 @@ describe('shallow', () => {
});

it('is instrospectable through context API', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
Expand Down Expand Up @@ -952,7 +953,7 @@ describe('shallow', () => {
});

describe('.setContext(newContext)', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
Expand Down Expand Up @@ -1272,7 +1273,7 @@ describe('shallow', () => {
const emptyRenderValues = generateEmptyRenderData();

itWithData(emptyRenderValues, 'when a React class component returns: ', (data) => {
const Foo = React.createClass({
const Foo = createClass({
render() {
return data.value;
},
Expand Down Expand Up @@ -3907,15 +3908,15 @@ describe('shallow', () => {
});
});

describe('React.createClass', () => {
describe('createClass', () => {
it('should return the name of the node', () => {
const Foo = React.createClass({
const Foo = createClass({
displayName: 'CustomWrapper',
render() {
return <div />;
},
});
const Wrapper = React.createClass({
const Wrapper = createClass({
render() {
return <Foo />;
},
Expand Down Expand Up @@ -3953,14 +3954,14 @@ describe('shallow', () => {
});
});

describe('React.createClass', () => {
describe('createClass', () => {
it('should return the name of the node', () => {
const Foo = React.createClass({
const Foo = createClass({
render() {
return <div />;
},
});
const Wrapper = React.createClass({
const Wrapper = createClass({
render() {
return <Foo />;
},
Expand Down
9 changes: 5 additions & 4 deletions test/staticRender-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { expect } from 'chai';
import { describeWithDOM, describeIf } from './_helpers';
import { render } from '../src/';
import { REACT013 } from '../src/version';
import { createClass } from '../src/react-compat';

describeWithDOM('render', () => {
describeIf(!REACT013, 'context', () => {
it('can pass in context', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
Expand All @@ -22,15 +23,15 @@ describeWithDOM('render', () => {
expect(wrapper.text()).to.equal('foo');
});
it('can pass context to the child of mounted component', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
},
});
const ComplexComponent = React.createClass({
const ComplexComponent = createClass({
render() {
return <div><SimpleComponent /></div>;
},
Expand All @@ -45,7 +46,7 @@ describeWithDOM('render', () => {
expect(wrapper.children().first().text()).to.equal('foo');
});
it('should not throw if context is passed in but contextTypes is missing', () => {
const SimpleComponent = React.createClass({
const SimpleComponent = createClass({
render() {
return <div>{this.context.name}</div>;
},
Expand Down

0 comments on commit fe21976

Please sign in to comment.