Support unmounting in ReactShallowRenderer

Reviewers: @sebmarkbage, @zpao

Test Plan:

```
$ npm test ReactTestUtils
```
This commit is contained in:
yungsters
2015-02-18 17:45:42 -08:00
parent e952869ff8
commit e9e33b984f
2 changed files with 24 additions and 2 deletions
+7 -2
View File
@@ -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();
+17
View File
@@ -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() {