Skip to content

Commit

Permalink
Update tests to not warn due to moved PropTypes and shallowRenderer (f…
Browse files Browse the repository at this point in the history
…acebook#9486)

* Update tests to not warn due to moved PropTypes and shallowRenderer

We added some warnings in v15.5 for calling `React.PropTypes` and
calling the shallow renderer from the wrong place. These warnings were
causing test failures, and now they are fixed.

Most of these were for the `React.PropTypes` change.

* tweak from running prettier

* Final tweaks to get tests passing

**what is the change?:**
Updated 'PropTypes' and 'shallow renderer' syntax in a couple more
places to get tests passing.

**why make this change?:**
In order to verify any changes to the 15.6 and 15.* branches in general
we should have tests passing.

**test plan:**
`npm run test`

**issue:**
facebook#9410
  • Loading branch information
flarnie committed Jun 7, 2017
1 parent 7ae4805 commit 4ed44a0
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 85 deletions.
2 changes: 1 addition & 1 deletion scripts/jest/ts-preprocessor.js
Expand Up @@ -28,7 +28,7 @@ function compile(content, contentFilename) {
// the file path into backslashes on Windows.
filename = path.normalize(filename);
var reactRegex = new RegExp(
path.join('/', '(?:React|ReactDOM)(?:\.d)?\.ts$')
path.join('/', '(?:React|ReactDOM|PropTypes)(?:\.d)?\.ts$')
);

var jestRegex = /jest\.d\.ts/;
Expand Down
25 changes: 13 additions & 12 deletions src/addons/__tests__/renderSubtreeIntoContainer-test.js
Expand Up @@ -11,6 +11,7 @@

'use strict';

var PropTypes = require('prop-types');
var React = require('React');
var ReactDOM = require('ReactDOM');
var ReactTestUtils = require('ReactTestUtils');
Expand All @@ -22,7 +23,7 @@ describe('renderSubtreeIntoContainer', () => {

class Component extends React.Component {
static contextTypes = {
foo: React.PropTypes.string.isRequired,
foo: PropTypes.string.isRequired,
};

render() {
Expand All @@ -32,7 +33,7 @@ describe('renderSubtreeIntoContainer', () => {

class Parent extends React.Component {
static childContextTypes = {
foo: React.PropTypes.string.isRequired,
foo: PropTypes.string.isRequired,
};

getChildContext() {
Expand Down Expand Up @@ -63,7 +64,7 @@ describe('renderSubtreeIntoContainer', () => {

class Component extends React.Component {
static contextTypes = {
foo: React.PropTypes.string.isRequired,
foo: PropTypes.string.isRequired,
};

render() {
Expand All @@ -76,7 +77,7 @@ describe('renderSubtreeIntoContainer', () => {
// eslint-disable-next-line no-unused-vars
class Parent extends React.Component {
static childContextTypes = {
foo: React.PropTypes.string.isRequired,
foo: PropTypes.string.isRequired,
};

getChildContext() {
Expand Down Expand Up @@ -104,8 +105,8 @@ describe('renderSubtreeIntoContainer', () => {

class Component extends React.Component {
static contextTypes = {
foo: React.PropTypes.string.isRequired,
getFoo: React.PropTypes.func.isRequired,
foo: PropTypes.string.isRequired,
getFoo: PropTypes.func.isRequired,
};

render() {
Expand All @@ -115,8 +116,8 @@ describe('renderSubtreeIntoContainer', () => {

class Parent extends React.Component {
static childContextTypes = {
foo: React.PropTypes.string.isRequired,
getFoo: React.PropTypes.func.isRequired,
foo: PropTypes.string.isRequired,
getFoo: PropTypes.func.isRequired,
};

state = {
Expand Down Expand Up @@ -156,8 +157,8 @@ describe('renderSubtreeIntoContainer', () => {

class Component extends React.Component {
static contextTypes = {
foo: React.PropTypes.string.isRequired,
getFoo: React.PropTypes.func.isRequired,
foo: PropTypes.string.isRequired,
getFoo: PropTypes.func.isRequired,
};

render() {
Expand All @@ -167,8 +168,8 @@ describe('renderSubtreeIntoContainer', () => {

class Parent extends React.Component {
static childContextTypes = {
foo: React.PropTypes.string.isRequired,
getFoo: React.PropTypes.func.isRequired,
foo: PropTypes.string.isRequired,
getFoo: PropTypes.func.isRequired,
};

getChildContext() {
Expand Down
24 changes: 13 additions & 11 deletions src/isomorphic/classic/__tests__/ReactContextValidator-test.js
Expand Up @@ -17,6 +17,7 @@

'use strict';

var PropTypes;
var React;
var ReactDOM;
var ReactTestUtils;
Expand All @@ -34,6 +35,7 @@ describe('ReactContextValidator', () => {
React = require('React');
ReactDOM = require('ReactDOM');
ReactTestUtils = require('ReactTestUtils');
PropTypes = require('prop-types');
reactComponentExpect = require('reactComponentExpect');
});

Expand All @@ -47,7 +49,7 @@ describe('ReactContextValidator', () => {
}
}
Component.contextTypes = {
foo: React.PropTypes.string,
foo: PropTypes.string,
};

class ComponentInFooBarContext extends React.Component {
Expand All @@ -63,8 +65,8 @@ describe('ReactContextValidator', () => {
}
}
ComponentInFooBarContext.childContextTypes = {
foo: React.PropTypes.string,
bar: React.PropTypes.number,
foo: PropTypes.string,
bar: PropTypes.number,
};

var instance = ReactTestUtils.renderIntoDocument(
Expand Down Expand Up @@ -94,8 +96,8 @@ describe('ReactContextValidator', () => {
}
}
Parent.childContextTypes = {
foo: React.PropTypes.string.isRequired,
bar: React.PropTypes.string.isRequired,
foo: PropTypes.string.isRequired,
bar: PropTypes.string.isRequired,
};

class Component extends React.Component {
Expand All @@ -122,7 +124,7 @@ describe('ReactContextValidator', () => {
}
}
Component.contextTypes = {
foo: React.PropTypes.string,
foo: PropTypes.string,
};

var container = document.createElement('div');
Expand All @@ -143,7 +145,7 @@ describe('ReactContextValidator', () => {
}
}
Component.contextTypes = {
foo: React.PropTypes.string.isRequired,
foo: PropTypes.string.isRequired,
};

ReactTestUtils.renderIntoDocument(<Component />);
Expand All @@ -168,7 +170,7 @@ describe('ReactContextValidator', () => {
}
}
ComponentInFooStringContext.childContextTypes = {
foo: React.PropTypes.string,
foo: PropTypes.string,
};

ReactTestUtils.renderIntoDocument(
Expand All @@ -190,7 +192,7 @@ describe('ReactContextValidator', () => {
}
}
ComponentInFooNumberContext.childContextTypes = {
foo: React.PropTypes.number,
foo: PropTypes.number,
};

ReactTestUtils.renderIntoDocument(
Expand Down Expand Up @@ -220,8 +222,8 @@ describe('ReactContextValidator', () => {
}
}
Component.childContextTypes = {
foo: React.PropTypes.string.isRequired,
bar: React.PropTypes.number,
foo: PropTypes.string.isRequired,
bar: PropTypes.number,
};

ReactTestUtils.renderIntoDocument(<Component testContext={{bar: 123}} />);
Expand Down
12 changes: 7 additions & 5 deletions src/isomorphic/classic/class/__tests__/ReactClass-test.js
Expand Up @@ -14,12 +14,14 @@
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', () => {
Expand Down Expand Up @@ -212,13 +214,13 @@ describe('ReactClass-spec', () => {
React.createClass({
mixins: [{}],
propTypes: {
foo: React.PropTypes.string,
foo: PropTypes.string,
},
contextTypes: {
foo: React.PropTypes.string,
foo: PropTypes.string,
},
childContextTypes: {
foo: React.PropTypes.string,
foo: PropTypes.string,
},
render: function() {
return <div />;
Expand Down Expand Up @@ -292,7 +294,7 @@ describe('ReactClass-spec', () => {
it('renders based on context getInitialState', () => {
var Foo = React.createClass({
contextTypes: {
className: React.PropTypes.string,
className: PropTypes.string,
},
getInitialState() {
return {className: this.context.className};
Expand All @@ -304,7 +306,7 @@ describe('ReactClass-spec', () => {

var Outer = React.createClass({
childContextTypes: {
className: React.PropTypes.string,
className: PropTypes.string,
},
getChildContext() {
return {className: 'foo'};
Expand Down
12 changes: 7 additions & 5 deletions src/isomorphic/classic/class/__tests__/ReactCreateClass-test.js
Expand Up @@ -11,13 +11,15 @@

'use strict';

var PropTypes;
var React;
var ReactDOM;
var ReactTestUtils;
var createReactClass;

describe('ReactClass-spec', () => {
beforeEach(() => {
PropTypes = require('prop-types');
React = require('React');
ReactDOM = require('ReactDOM');
ReactTestUtils = require('ReactTestUtils');
Expand Down Expand Up @@ -199,13 +201,13 @@ describe('ReactClass-spec', () => {
createReactClass({
mixins: [{}],
propTypes: {
foo: React.PropTypes.string,
foo: PropTypes.string,
},
contextTypes: {
foo: React.PropTypes.string,
foo: PropTypes.string,
},
childContextTypes: {
foo: React.PropTypes.string,
foo: PropTypes.string,
},
render: function() {
return <div />;
Expand Down Expand Up @@ -279,7 +281,7 @@ describe('ReactClass-spec', () => {
it('renders based on context getInitialState', () => {
var Foo = createReactClass({
contextTypes: {
className: React.PropTypes.string,
className: PropTypes.string,
},
getInitialState() {
return {className: this.context.className};
Expand All @@ -291,7 +293,7 @@ describe('ReactClass-spec', () => {

var Outer = createReactClass({
childContextTypes: {
className: React.PropTypes.string,
className: PropTypes.string,
},
getChildContext() {
return {className: 'foo'};
Expand Down
Expand Up @@ -11,6 +11,7 @@

'use strict';

var PropTypes;
var React;
var ReactDOM;
var ReactTestUtils;
Expand All @@ -22,6 +23,7 @@ describe('ReactElementClone', () => {
React = require('React');
ReactDOM = require('ReactDOM');
ReactTestUtils = require('ReactTestUtils');
PropTypes = require('prop-types');

// NOTE: We're explicitly not using JSX here. This is intended to test
// classic JS without JSX.
Expand Down Expand Up @@ -293,7 +295,7 @@ describe('ReactElementClone', () => {
}
}
Component.propTypes = {
color: React.PropTypes.string.isRequired,
color: PropTypes.string.isRequired,
};
class Parent extends React.Component {
render() {
Expand Down
Expand Up @@ -14,6 +14,7 @@
// NOTE: We're explicitly not using JSX in this file. This is intended to test
// classic JS without JSX.

var PropTypes;
var React;
var ReactDOM;
var ReactTestUtils;
Expand All @@ -31,6 +32,7 @@ describe('ReactElementValidator', () => {
React = require('React');
ReactDOM = require('ReactDOM');
ReactTestUtils = require('ReactTestUtils');
PropTypes = require('prop-types');
ComponentClass = class extends React.Component {
render() {
return React.createElement('div');
Expand Down Expand Up @@ -250,7 +252,7 @@ describe('ReactElementValidator', () => {
return React.createElement('div', null, 'My color is ' + props.color);
}
MyComp.propTypes = {
color: React.PropTypes.string,
color: PropTypes.string,
};
function ParentComp() {
return React.createElement(MyComp, {color: 123});
Expand Down Expand Up @@ -339,7 +341,7 @@ describe('ReactElementValidator', () => {
return React.createElement('span', null, this.props.prop);
}
}
Component.propTypes = {prop: React.PropTypes.string.isRequired};
Component.propTypes = {prop: PropTypes.string.isRequired};
Component.defaultProps = {prop: null};

ReactTestUtils.renderIntoDocument(React.createElement(Component));
Expand All @@ -360,7 +362,7 @@ describe('ReactElementValidator', () => {
return React.createElement('span', null, this.props.prop);
}
}
Component.propTypes = {prop: React.PropTypes.string.isRequired};
Component.propTypes = {prop: PropTypes.string.isRequired};
Component.defaultProps = {prop: 'text'};

ReactTestUtils.renderIntoDocument(
Expand All @@ -384,7 +386,7 @@ describe('ReactElementValidator', () => {
}
}
Component.propTypes = {
prop: React.PropTypes.string.isRequired,
prop: PropTypes.string.isRequired,
};

ReactTestUtils.renderIntoDocument(React.createElement(Component));
Expand Down Expand Up @@ -424,7 +426,7 @@ describe('ReactElementValidator', () => {
}
}
Component.propTypes = {
myProp: React.PropTypes.shape,
myProp: PropTypes.shape,
};

ReactTestUtils.renderIntoDocument(
Expand Down
19 changes: 19 additions & 0 deletions src/isomorphic/modern/class/PropTypes.d.ts
@@ -0,0 +1,19 @@
/*!
* 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.
*/

/**
* TypeScript Definition File for React.
*
* Full type definitions are not yet officially supported. These are mostly
* just helpers for the unit test.
*/

declare module 'prop-types' {
export var string : any;
}

0 comments on commit 4ed44a0

Please sign in to comment.