Skip to content

Commit

Permalink
Fix setProps not passing old context.
Browse files Browse the repository at this point in the history
  • Loading branch information
srph committed Jan 15, 2016
1 parent e56b44b commit 6ee6108
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class ShallowWrapper {
this.single(() => {
withSetStateAllowed(() => {
this.unrendered = React.cloneElement(this.unrendered, props);
this.renderer.render(this.unrendered);
this.renderer.render(this.unrendered, this.options.context);
this.update();
});
});
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,24 @@ describe('shallow', () => {
expect(wrapper.props().d).to.equal('e');
});

it('should pass in old context', ( ) => {
class Foo extends React.Component {
render() {
return (
<div>{this.context.x}</div>
);
}
}

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

const context = { x: 'yolo' };
const wrapper = shallow(<Foo x={5} />, { context });
expect(wrapper.first('div').text(), 'value of context.x should be printed').to.equal('yolo');

wrapper.setProps({ x: 5 }); // Just force a re-render
expect(wrapper.first('div').text(), 'context should still be the same').to.equal('yolo');
});
});

describe('.setContext(newContext)', () => {
Expand Down

0 comments on commit 6ee6108

Please sign in to comment.