Skip to content

Commit

Permalink
Support unmounting in ReactShallowRenderer
Browse files Browse the repository at this point in the history
Reviewers: @sebmarkbage, @zpao

Test Plan:

```
$ npm test ReactTestUtils
```
  • Loading branch information
yungsters committed Feb 19, 2015
1 parent e952869 commit e9e33b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ var NoopInternalComponent = function(element) {
this._currentElement = element === null || element === false ?
ReactEmptyComponent.emptyElement :
element;
}
};

NoopInternalComponent.prototype = {

Expand All @@ -349,7 +349,6 @@ NoopInternalComponent.prototype = {
},

unmountComponent: function() {

}

};
Expand All @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions src/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ describe('ReactTestUtils', function() {
]);
});

it('should have shallow unmounting', function() {
var componentWillUnmount = mocks.getMockFunction();

var SomeComponent = React.createClass({
render: function() {
return <div />;
},
componentWillUnmount
});

var shallowRenderer = ReactTestUtils.createRenderer();
shallowRenderer.render(<SomeComponent />, {});
shallowRenderer.unmount();

expect(componentWillUnmount).toBeCalled();
});

it('can shallow render to null', function() {
var SomeComponent = React.createClass({
render: function() {
Expand Down

0 comments on commit e9e33b9

Please sign in to comment.