mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Perform transaction around shallow render to run lifecycle methods
This commit is contained in:
1 parent
6ff4ba9512
commit
107e3014ef
2 files changed
+41
-1
No files matched your search
@@ -411,7 +411,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);
|
||||
};
|
||||
|
||||
|
||||
@@ -91,6 +91,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() {
|
||||
|
||||
Reference in new issue
Block a user