Skip to content

Commit

Permalink
Add prop-types as a regular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 12, 2017
1 parent 1c932cb commit 49e0825
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 42 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ the following npm modules installed if they were not already:

```bash
npm i --save-dev react-dom
npm i --save-dev prop-types
```


Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils",
"react:13": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@0.13 && npm install",
"react:14": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@0.14 react-dom@0.14 react-addons-test-utils@0.14 && npm install",
"react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15 prop-types@15 create-react-class@15 react-test-renderer@15 && npm install",
"react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15 create-react-class@15 react-test-renderer@15 && npm install",
"docs:clean": "rimraf _book",
"docs:prepare": "gitbook install",
"docs:build": "npm run docs:prepare && gitbook build",
Expand Down Expand Up @@ -60,6 +60,7 @@
"object.assign": "^4.0.4",
"object.entries": "^1.0.3",
"object.values": "^1.0.3",
"prop-types": "^15.5.4",
"uuid": "^2.0.3"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/ReactWrapperComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import objectAssign from 'object.assign';
import { PropTypes, createClass } from './react-compat';
import { createClass } from './react-compat';

/* eslint react/forbid-prop-types: 0 */

Expand Down
5 changes: 0 additions & 5 deletions src/react-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ let childrenToArray;
let renderWithOptions;
let unmountComponentAtNode;
let batchedUpdates;
let PropTypes;
let createClass;
let shallowRendererFactory;

Expand Down Expand Up @@ -179,12 +178,9 @@ if (REACT013) {
}

if (REACT155) {
// eslint-disable-next-line import/no-extraneous-dependencies
PropTypes = require('prop-types');
// eslint-disable-next-line import/no-extraneous-dependencies
createClass = require('create-react-class');
} else {
PropTypes = React.PropTypes;
createClass = React.createClass;
}

Expand Down Expand Up @@ -223,6 +219,5 @@ export {
renderWithOptions,
unmountComponentAtNode,
batchedUpdates,
PropTypes,
createClass,
};
27 changes: 14 additions & 13 deletions test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* globals document */

import React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import sinon from 'sinon';
import { batchedUpdates } from '../src/react-compat';
Expand All @@ -25,7 +26,7 @@ describeWithDOM('mount', () => {
it('can pass in context', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -40,7 +41,7 @@ describeWithDOM('mount', () => {
it('can pass context to the child of mounted component', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -53,7 +54,7 @@ describeWithDOM('mount', () => {
});

const childContextTypes = {
name: React.PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
};
const context = { name: 'foo' };
const wrapper = mount(<ComplexComponent />, { context, childContextTypes });
Expand All @@ -74,7 +75,7 @@ describeWithDOM('mount', () => {
it('is instrospectable through context API', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -93,7 +94,7 @@ describeWithDOM('mount', () => {
const SimpleComponent = (props, context) => (
<div>{context.name}</div>
);
SimpleComponent.contextTypes = { name: React.PropTypes.string };
SimpleComponent.contextTypes = { name: PropTypes.string };

const context = { name: 'foo' };
const wrapper = mount(<SimpleComponent />, { context });
Expand All @@ -104,14 +105,14 @@ describeWithDOM('mount', () => {
const SimpleComponent = (props, context) => (
<div>{context.name}</div>
);
SimpleComponent.contextTypes = { name: React.PropTypes.string };
SimpleComponent.contextTypes = { name: PropTypes.string };

const ComplexComponent = () => (
<div><SimpleComponent /></div>
);

const childContextTypes = {
name: React.PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
};

const context = { name: 'foo' };
Expand All @@ -132,7 +133,7 @@ describeWithDOM('mount', () => {
const SimpleComponent = (props, context) => (
<div>{context.name}</div>
);
SimpleComponent.contextTypes = { name: React.PropTypes.string };
SimpleComponent.contextTypes = { name: PropTypes.string };

const context = { name: 'foo' };
const wrapper = mount(<SimpleComponent />, { context });
Expand All @@ -150,7 +151,7 @@ describeWithDOM('mount', () => {
);

Foo.contextTypes = {
_: React.PropTypes.string,
_: PropTypes.string,
};

const wrapper = mount(<Foo foo="qux" />, {
Expand Down Expand Up @@ -1098,7 +1099,7 @@ describeWithDOM('mount', () => {
it('should set context for a component multiple times', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -1117,7 +1118,7 @@ describeWithDOM('mount', () => {
it('should throw if it is called when shallow didn’t include context', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -1136,7 +1137,7 @@ describeWithDOM('mount', () => {
const SimpleComponent = (props, context) => (
<div>{context.name}</div>
);
SimpleComponent.contextTypes = { name: React.PropTypes.string };
SimpleComponent.contextTypes = { name: PropTypes.string };

const context = { name: 'foo' };
const wrapper = mount(<SimpleComponent />, { context });
Expand All @@ -1151,7 +1152,7 @@ describeWithDOM('mount', () => {
const SimpleComponent = (props, context) => (
<div>{context.name}</div>
);
SimpleComponent.contextTypes = { name: React.PropTypes.string };
SimpleComponent.contextTypes = { name: PropTypes.string };

const wrapper = mount(<SimpleComponent />);
expect(() => wrapper.setContext({ name: 'bar' })).to.throw(
Expand Down
37 changes: 19 additions & 18 deletions test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import sinon from 'sinon';

Expand All @@ -12,7 +13,7 @@ describe('shallow', () => {
it('can pass in context', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -38,7 +39,7 @@ describe('shallow', () => {
it('is instrospectable through context API', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -57,7 +58,7 @@ describe('shallow', () => {
const SimpleComponent = (props, context) => (
<div>{context.name}</div>
);
SimpleComponent.contextTypes = { name: React.PropTypes.string };
SimpleComponent.contextTypes = { name: PropTypes.string };

const context = { name: 'foo' };
const wrapper = shallow(<SimpleComponent />, { context });
Expand All @@ -77,7 +78,7 @@ describe('shallow', () => {
const SimpleComponent = (props, context) => (
<div>{context.name}</div>
);
SimpleComponent.contextTypes = { name: React.PropTypes.string };
SimpleComponent.contextTypes = { name: PropTypes.string };

const wrapper = shallow(<SimpleComponent />, { context });

Expand Down Expand Up @@ -892,7 +893,7 @@ describe('shallow', () => {
}
}

Foo.contextTypes = { x: React.PropTypes.string };
Foo.contextTypes = { x: PropTypes.string };

const context = { x: 'yolo' };
const wrapper = shallow(<Foo x={5} />, { context });
Expand Down Expand Up @@ -938,7 +939,7 @@ describe('shallow', () => {
const Foo = (props, context) => (
<div>{context.x}</div>
);
Foo.contextTypes = { x: React.PropTypes.string };
Foo.contextTypes = { x: PropTypes.string };

const context = { x: 'yolo' };
const wrapper = shallow(<Foo x={5} />, { context });
Expand All @@ -953,7 +954,7 @@ describe('shallow', () => {
describe('.setContext(newContext)', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand Down Expand Up @@ -982,7 +983,7 @@ describe('shallow', () => {
const SFC = (props, context) => (
<div>{context.name}</div>
);
SFC.contextTypes = { name: React.PropTypes.string };
SFC.contextTypes = { name: PropTypes.string };

it('should set context for a component multiple times', () => {
const context = { name: 'foo' };
Expand Down Expand Up @@ -2309,7 +2310,7 @@ describe('shallow', () => {
}
}
Bar.contextTypes = {
name: React.PropTypes.string,
name: PropTypes.string,
};
class Foo extends React.Component {
render() {
Expand Down Expand Up @@ -2355,7 +2356,7 @@ describe('shallow', () => {
}
}
Bar.contextTypes = {
name: React.PropTypes.string,
name: PropTypes.string,
};
class Foo extends React.Component {
render() {
Expand Down Expand Up @@ -2399,7 +2400,7 @@ describe('shallow', () => {
const Bar = (props, context) => (
<div>{context.name}</div>
);
Bar.contextTypes = { name: React.PropTypes.string };
Bar.contextTypes = { name: PropTypes.string };
const Foo = () => (
<div>
<Bar />
Expand Down Expand Up @@ -2430,7 +2431,7 @@ describe('shallow', () => {
const Bar = (props, context) => (
<div>{context.name}</div>
);
Bar.contextTypes = { name: React.PropTypes.string };
Bar.contextTypes = { name: PropTypes.string };
const Foo = () => (
<div>
<Bar />
Expand Down Expand Up @@ -2921,7 +2922,7 @@ describe('shallow', () => {
}
}
Foo.contextTypes = {
foo: React.PropTypes.string,
foo: PropTypes.string,
};

const wrapper = shallow(
Expand Down Expand Up @@ -3145,7 +3146,7 @@ describe('shallow', () => {
}
}
Foo.contextTypes = {
foo: React.PropTypes.string,
foo: PropTypes.string,
};

const wrapper = shallow(
Expand Down Expand Up @@ -3304,7 +3305,7 @@ describe('shallow', () => {
}
}
Foo.contextTypes = {
foo: React.PropTypes.string,
foo: PropTypes.string,
};
const wrapper = shallow(
<Foo foo="props" />,
Expand Down Expand Up @@ -3363,7 +3364,7 @@ describe('shallow', () => {
}
}
Foo.contextTypes = {
foo: React.PropTypes.string,
foo: PropTypes.string,
};
const wrapper = shallow(
<Foo />,
Expand Down Expand Up @@ -4005,7 +4006,7 @@ describe('shallow', () => {
return <RendersDOM />;
}
}
WrapsRendersDOM.contextTypes = { foo: React.PropTypes.string };
WrapsRendersDOM.contextTypes = { foo: PropTypes.string };
class DoubleWrapsRendersDOM extends React.Component {
render() {
return <WrapsRendersDOM />;
Expand All @@ -4016,7 +4017,7 @@ describe('shallow', () => {
return <WrapsRendersDOM />;
}
}
ContextWrapsRendersDOM.contextTypes = { foo: React.PropTypes.string };
ContextWrapsRendersDOM.contextTypes = { foo: PropTypes.string };

it('throws on a DOM node', () => {
const wrapper = shallow(<RendersDOM />);
Expand Down
7 changes: 4 additions & 3 deletions test/staticRender-spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { describeWithDOM, describeIf } from './_helpers';
import { render } from '../src/';
Expand All @@ -9,7 +10,7 @@ describeWithDOM('render', () => {
it('can pass in context', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -23,7 +24,7 @@ describeWithDOM('render', () => {
it('can pass context to the child of mounted component', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
Expand All @@ -36,7 +37,7 @@ describeWithDOM('render', () => {
});

const childContextTypes = {
name: React.PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
};
const context = { name: 'foo' };
const wrapper = render(<ComplexComponent />, { context, childContextTypes });
Expand Down

0 comments on commit 49e0825

Please sign in to comment.