mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Support unmounting in ReactShallowRenderer
Reviewers: @sebmarkbage, @zpao Test Plan: ``` $ npm test ReactTestUtils ```
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user