Merge pull request #4993 from jsdf/shallow-render-lifecycle

Run all component lifecycle methods when shallow rendering
This commit is contained in:
Ben Alpert committed 2015-11-02 18:16:55 -08:00
commit d2888798f0
2 files changed
+41 -1

No files matched your search

+1 -1
View File
@@ -433,7 +433,7 @@ ReactShallowRenderer.prototype.render = function(element, context) {
context = emptyObject;
}
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(false);
this._render(element, transaction, context);
transaction.perform(this._render, this, element, transaction, context);
ReactUpdates.ReactReconcileTransaction.release(transaction);
};
+40
View File
@@ -87,6 +87,46 @@ describe('ReactTestUtils', function() {
expect(componentWillUnmount).toBeCalled();
});
it('should run all lifecycle methods', function() {
var componentWillMount = mocks.getMockFunction();
var componentDidMount = mocks.getMockFunction();
var componentWillReceiveProps = mocks.getMockFunction();
var shouldComponentUpdate = mocks.getMockFunction();
var componentWillUpdate = mocks.getMockFunction();
var componentDidUpdate = mocks.getMockFunction();
var componentWillUnmount = mocks.getMockFunction();
var SomeComponent = React.createClass({
render: function() {
return <SomeComponent onChange={() => this.setState({a: 1})} />;
},
componentWillMount,
componentDidMount,
componentWillReceiveProps,
shouldComponentUpdate() {
shouldComponentUpdate();
return true;
},
componentWillUpdate,
componentDidUpdate,
componentWillUnmount,
});
var shallowRenderer = ReactTestUtils.createRenderer();
shallowRenderer.render(<SomeComponent />);
shallowRenderer.getRenderOutput().props.onChange();
shallowRenderer.render(<SomeComponent />);
shallowRenderer.unmount();
expect(componentWillMount).toBeCalled();
expect(componentDidMount).toBeCalled();
expect(componentWillReceiveProps).toBeCalled();
expect(shouldComponentUpdate).toBeCalled();
expect(componentWillUpdate).toBeCalled();
expect(componentDidUpdate).toBeCalled();
expect(componentWillUnmount).toBeCalled();
});
it('can shallow render to null', function() {
var SomeComponent = React.createClass({
render: function() {