Error when unmountComponentAtNode receives non-node

This commit is contained in:
Justin Woo
2014-08-24 10:53:15 -04:00
parent 9ef2b4e5d9
commit 9c8ddb3316
2 changed files with 20 additions and 0 deletions
+8
View File
@@ -465,6 +465,14 @@ var ReactMount = {
'componentDidUpdate.'
);
invariant(
container && (
container.nodeType === ELEMENT_NODE_TYPE ||
container.nodeType === DOC_NODE_TYPE
),
'unmountComponentAtNode(...): Target container is not a DOM element.'
);
var reactRootID = getReactRootID(container);
var component = instancesByReactRootID[reactRootID];
if (!component) {
@@ -38,6 +38,18 @@ describe('ReactMount', function() {
});
});
describe('unmountComponentAtNode', function() {
it('throws when given a non-node', function() {
var nodeArray = document.getElementsByTagName('div');
expect(function() {
React.unmountComponentAtNode(nodeArray);
}).toThrow(
'Invariant Violation: unmountComponentAtNode(...): Target container ' +
'is not a DOM element.'
);
});
});
it('throws when given a string', function() {
expect(function() {
ReactTestUtils.renderIntoDocument('div');