Merge pull request #5330 from laskos/fix-shallow-rendering-function-refs

Fix shallow renderer with ref as function
(cherry picked from commit 1a6d1e74e0)
This commit is contained in:
Ben Alpert
2015-11-17 23:53:00 -08:00
committed by Paul O’Shannessy
parent cde2de3ce7
commit 22c9562cd9
2 changed files with 28 additions and 0 deletions
+3
View File
@@ -384,6 +384,9 @@ NoopInternalComponent.prototype = {
unmountComponent: function() {
},
getPublicInstance: function() {
return null;
},
};
var ShallowComponentWrapper = function() { };
+25
View File
@@ -176,6 +176,31 @@ describe('ReactTestUtils', function() {
expect(result).toEqual(<div />);
});
it('can shallowly render components with ref as function', function() {
var SimpleComponent = React.createClass({
getInitialState: function() {
return {clicked: false};
},
handleUserClick: function() {
this.setState({ clicked: true });
},
render: function() {
return <div ref={() => {}} onClick={this.handleUserClick} className={this.state.clicked ? 'clicked' : ''}></div>;
},
});
var shallowRenderer = ReactTestUtils.createRenderer();
shallowRenderer.render(<SimpleComponent />);
var result = shallowRenderer.getRenderOutput();
expect(result.type).toEqual('div');
expect(result.props.className).toEqual('');
result.props.onClick();
result = shallowRenderer.getRenderOutput();
expect(result.type).toEqual('div');
expect(result.props.className).toEqual('clicked');
});
it('can pass context when shallowly rendering', function() {
var SimpleComponent = React.createClass({
contextTypes: {