diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index 467b6682c2..8b5eb5fecd 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -427,13 +427,17 @@ ReactShallowRenderer.prototype.render = function(element, context) { if (!context) { context = emptyObject; } - var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true); - this._render(element, transaction, context); - ReactUpdates.ReactReconcileTransaction.release(transaction); + ReactUpdates.batchedUpdates(_batchedRender, this, element, context); return this.getRenderOutput(); }; +function _batchedRender(renderer, element, context) { + var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true); + renderer._render(element, transaction, context); + ReactUpdates.ReactReconcileTransaction.release(transaction); +} + ReactShallowRenderer.prototype.getRenderOutput = function() { return ( (this._instance && this._instance._renderedComponent && diff --git a/src/test/__tests__/ReactTestUtils-test.js b/src/test/__tests__/ReactTestUtils-test.js index 86fc3d13f9..1fb6956ffa 100644 --- a/src/test/__tests__/ReactTestUtils-test.js +++ b/src/test/__tests__/ReactTestUtils-test.js @@ -217,6 +217,21 @@ describe('ReactTestUtils', function() { expect(result.props.className).toEqual('clicked'); }); + it('can setState in componentWillMount when shallow rendering', function() { + var SimpleComponent = React.createClass({ + componentWillMount() { + this.setState({groovy: 'doovy'}); + }, + render() { + return