mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
committed by
Paul O’Shannessy
parent
cde2de3ce7
commit
22c9562cd9
@@ -384,6 +384,9 @@ NoopInternalComponent.prototype = {
|
||||
unmountComponent: function() {
|
||||
},
|
||||
|
||||
getPublicInstance: function() {
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
||||
var ShallowComponentWrapper = function() { };
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user