diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index b3c8a9940c..54f84c8bb7 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -334,7 +334,7 @@ var NoopInternalComponent = function(element) { this._currentElement = element === null || element === false ? ReactEmptyComponent.emptyElement : element; -} +}; NoopInternalComponent.prototype = { @@ -349,7 +349,6 @@ NoopInternalComponent.prototype = { }, unmountComponent: function() { - } }; @@ -374,6 +373,12 @@ ReactShallowRenderer.prototype.render = function(element, context) { ReactUpdates.ReactReconcileTransaction.release(transaction); }; +ReactShallowRenderer.prototype.unmount = function() { + if (this._instance) { + this._instance.unmountComponent(); + } +}; + ReactShallowRenderer.prototype._render = function(element, transaction, context) { if (!this._instance) { var rootID = ReactInstanceHandles.createReactRootID(); diff --git a/src/test/__tests__/ReactTestUtils-test.js b/src/test/__tests__/ReactTestUtils-test.js index 7c091bc994..fe817c4937 100644 --- a/src/test/__tests__/ReactTestUtils-test.js +++ b/src/test/__tests__/ReactTestUtils-test.js @@ -57,6 +57,23 @@ describe('ReactTestUtils', function() { ]); }); + it('should have shallow unmounting', function() { + var componentWillUnmount = mocks.getMockFunction(); + + var SomeComponent = React.createClass({ + render: function() { + return
; + }, + componentWillUnmount + }); + + var shallowRenderer = ReactTestUtils.createRenderer(); + shallowRenderer.render(, {}); + shallowRenderer.unmount(); + + expect(componentWillUnmount).toBeCalled(); + }); + it('can shallow render to null', function() { var SomeComponent = React.createClass({ render: function() {