Skip to content

Commit

Permalink
Wrapping all new context test into describeIf()
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterbmt authored and Son Hai Ngoc Tang committed Feb 21, 2017
1 parent 6d5b50f commit 4bd4a57
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions test/staticRender-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,38 @@ describeWithDOM('render', () => {
const wrapper = render(<SimpleComponent />, { context });
expect(wrapper.text()).to.equal('foo');
});
});
it('can pass context to the child of mounted component', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
},
});
const ComplexComponent = React.createClass({
render() {
return <div><SimpleComponent /></div>;
},
});
it('can pass context to the child of mounted component', () => {
const SimpleComponent = React.createClass({
contextTypes: {
name: React.PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
},
});
const ComplexComponent = React.createClass({
render() {
return <div><SimpleComponent /></div>;
},
});

const childContextTypes = {
name: React.PropTypes.string.isRequired,
};
const context = { name: 'foo' };
const wrapper = render(<ComplexComponent />, { context, childContextTypes });
expect(wrapper.children()).to.have.length(1);
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({
render() {
return <div>{this.context.name}</div>;
},
const childContextTypes = {
name: React.PropTypes.string.isRequired,
};
const context = { name: 'foo' };
const wrapper = render(<ComplexComponent />, { context, childContextTypes });
expect(wrapper.children()).to.have.length(1);
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({
render() {
return <div>{this.context.name}</div>;
},
});

const context = { name: 'foo' };
expect(() => render(<SimpleComponent />, { context })).to.not.throw(Error);
const context = { name: 'foo' };
expect(() => render(<SimpleComponent />, { context })).to.not.throw(Error);
});
});
});

0 comments on commit 4bd4a57

Please sign in to comment.