Skip to content

Commit

Permalink
codemodded tests from createClass to ES2015 classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyan Zhang committed Jul 21, 2016
1 parent fc04e85 commit f4fe06a
Show file tree
Hide file tree
Showing 47 changed files with 2,413 additions and 2,210 deletions.
142 changes: 70 additions & 72 deletions src/addons/__tests__/renderSubtreeIntoContainer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@ describe('renderSubtreeIntoContainer', function() {
it('should pass context when rendering subtree elsewhere', function() {
var portal = document.createElement('div');

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

render: function() {
render() {
return <div>{this.context.foo}</div>;
},
});
}
}

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

getChildContext: function() {
getChildContext() {
return {
foo: 'bar',
};
},
}

render: function() {
render() {
return null;
},
}

componentDidMount: function() {
componentDidMount() {
expect(function() {
renderSubtreeIntoContainer(this, <Component />, portal);
}.bind(this)).not.toThrow();
},
});
}
}

ReactTestUtils.renderIntoDocument(<Parent />);
expect(portal.firstChild.innerHTML).toBe('bar');
Expand All @@ -60,86 +60,84 @@ describe('renderSubtreeIntoContainer', function() {
it('should throw if parentComponent is invalid', function() {
var portal = document.createElement('div');

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

render: function() {
render() {
return <div>{this.context.foo}</div>;
},
});
}
}

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

getChildContext: function() {
getChildContext() {
return {
foo: 'bar',
};
},
}

render: function() {
render() {
return null;
},
}

componentDidMount: function() {
componentDidMount() {
expect(function() {
renderSubtreeIntoContainer(<Parent />, <Component />, portal);
}).toThrowError('parentComponentmust be a valid React Component');
},
});
}
}
});

it('should update context if it changes due to setState', function() {
var container = document.createElement('div');
document.body.appendChild(container);
var portal = document.createElement('div');

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

render: function() {
render() {
return <div>{this.context.foo + '-' + this.context.getFoo()}</div>;
},
});
}
}

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

getChildContext: function() {
state = {
bar: 'initial',
};

getChildContext() {
return {
foo: this.state.bar,
getFoo: () => this.state.bar,
};
},

getInitialState: function() {
return {
bar: 'initial',
};
},
}

render: function() {
render() {
return null;
},
}

componentDidMount: function() {
componentDidMount() {
renderSubtreeIntoContainer(this, <Component />, portal);
},
}

componentDidUpdate() {
renderSubtreeIntoContainer(this, <Component />, portal);
},
});
}
}

var instance = ReactDOM.render(<Parent />, container);
expect(portal.firstChild.innerHTML).toBe('initial-initial');
Expand All @@ -152,42 +150,42 @@ describe('renderSubtreeIntoContainer', function() {
document.body.appendChild(container);
var portal = document.createElement('div');

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

render: function() {
render() {
return <div>{this.context.foo + '-' + this.context.getFoo()}</div>;
},
});
}
}

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

getChildContext: function() {
getChildContext() {
return {
foo: this.props.bar,
getFoo: () => this.props.bar,
};
},
}

render: function() {
render() {
return null;
},
}

componentDidMount: function() {
componentDidMount() {
renderSubtreeIntoContainer(this, <Component />, portal);
},
}

componentDidUpdate() {
renderSubtreeIntoContainer(this, <Component />, portal);
},
});
}
}

ReactDOM.render(<Parent bar="initial" />, container);
expect(portal.firstChild.innerHTML).toBe('initial-initial');
Expand Down
26 changes: 12 additions & 14 deletions src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,17 @@ describe('ReactCSSTransitionGroup', function() {
});

it('should clear transition timeouts when unmounted', function() {
var Component = React.createClass({
render: function() {
class Component extends React.Component {
render() {
return (
<ReactCSSTransitionGroup
transitionName="yolo"
transitionEnterTimeout={500}>
{this.props.children}
</ReactCSSTransitionGroup>
);
},
});
}
}

ReactDOM.render(<Component/>, container);
ReactDOM.render(<Component><span key="yolo" id="yolo"/></Component>, container);
Expand All @@ -293,23 +293,21 @@ describe('ReactCSSTransitionGroup', function() {
});

it('should handle unmounted elements properly', function() {
var Child = React.createClass({
class Child extends React.Component {
render() {
if (!this.props.show) {
return null;
}
return <div />;
},
});
}
}

var Component = React.createClass({
getInitialState() {
return { showChild: true };
},
class Component extends React.Component {
state = { showChild: true };

componentDidMount() {
this.setState({ showChild: false });
},
}

render() {
return (
Expand All @@ -321,8 +319,8 @@ describe('ReactCSSTransitionGroup', function() {
<Child show={this.state.showChild} />
</ReactCSSTransitionGroup>
);
},
});
}
}

ReactDOM.render(<Component/>, container);

Expand Down
Loading

0 comments on commit f4fe06a

Please sign in to comment.