Skip to content

Instantly share code, notes, and snippets.

@jakubzitny
Created February 7, 2016 19:24
Show Gist options
  • Save jakubzitny/7b9d526f77b2865219d3 to your computer and use it in GitHub Desktop.
Save jakubzitny/7b9d526f77b2865219d3 to your computer and use it in GitHub Desktop.
it('can pass advanced context to the child of mounted component', () => {
const SimpleComponent = React.createClass({
contextTypes: {
ctx1: React.PropTypes.string.isRequired,
ctx2: React.PropTypes.string.isRequired,
},
render() {
return <div>{this.context.ctx1}{this.context.ctx2}</div>;
},
});
const ComplexComponent = React.createClass({
contextTypes: {
ctx1: React.PropTypes.string.isRequired,
},
render() {
return <div><SimpleComponent /><p>{this.context.ctx1}</p></div>;
},
});
const advancedContext = { ctx1: 'ctx1', ctx2: 'ctx2' };
const wrapper = mount(<ComplexComponent />, { context: advancedContext });
expect(wrapper.find(SimpleComponent)).to.have.length(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment