diff --git a/src/renderers/shared/reconciler/__tests__/ReactInstanceHandles-test.js b/src/renderers/shared/reconciler/__tests__/ReactInstanceHandles-test.js index f5dbc051ff..7cb1ba9d95 100644 --- a/src/renderers/shared/reconciler/__tests__/ReactInstanceHandles-test.js +++ b/src/renderers/shared/reconciler/__tests__/ReactInstanceHandles-test.js @@ -76,72 +76,84 @@ describe('ReactInstanceHandles', function() { describe('findComponentRoot', function() { it('should find the correct node with prefix sibling IDs', function() { - var parentNode = document.createElement('div'); - var childNodeA = document.createElement('div'); - var childNodeB = document.createElement('div'); - parentNode.appendChild(childNodeA); - parentNode.appendChild(childNodeB); - - ReactMount.setID(parentNode, '.0'); - ReactMount.setID(childNodeA, '.0.0'); - ReactMount.setID(childNodeB, '.0.0:1'); + var parentNode = ReactTestUtils.renderIntoDocument( +
+
+ {[
]} +
+ ); + var childNodeB = parentNode.childNodes[1]; expect( - ReactMount.findComponentRoot( - parentNode, - ReactMount.getID(childNodeB) + ReactMount.getNode( + getNodeID(childNodeB) ) ).toBe(childNodeB); }); it('should work around unidentified nodes', function() { - var parentNode = document.createElement('div'); - var childNodeA = document.createElement('div'); - var childNodeB = document.createElement('div'); - parentNode.appendChild(childNodeA); - parentNode.appendChild(childNodeB); + var parentNode = ReactTestUtils.renderIntoDocument( +
+ {[
]} +
+ ); + var childNodeB = parentNode.childNodes[0]; - ReactMount.setID(parentNode, '.0'); // No ID on `childNodeA`. - ReactMount.setID(childNodeB, '.0.0:1'); + var childNodeA = document.createElement('div'); + parentNode.insertBefore(childNodeA, childNodeB); expect( - ReactMount.findComponentRoot( - parentNode, - ReactMount.getID(childNodeB) + ReactMount.getNode( + getNodeID(childNodeB) ) ).toBe(childNodeB); }); it('should throw if a rendered element cannot be found', function() { - var parentNode = document.createElement('table'); - var childNodeA = document.createElement('tbody'); - var childNodeB = document.createElement('tr'); - parentNode.appendChild(childNodeA); - childNodeA.appendChild(childNodeB); + spyOn(console, 'error'); + var parentNode = ReactTestUtils.renderIntoDocument( + + +
+ ); + var childNodeA = parentNode.childNodes[0]; + var childNodeB; + if (childNodeA.tagName === 'TR') { + childNodeB = childNodeA; + // No ID on `childNodeA`, it was "rendered by the browser". + childNodeA = document.createElement('tbody'); + childNodeA.appendChild(childNodeB); + parentNode.appendChild(childNodeA); + } else { + childNodeB = childNodeA.childNodes[0]; + } + expect(childNodeA.tagName).toBe('TBODY'); - ReactMount.setID(parentNode, '.0'); - // No ID on `childNodeA`, it was "rendered by the browser". - ReactMount.setID(childNodeB, '.0.1:0'); - - expect(ReactMount.findComponentRoot( - parentNode, - ReactMount.getID(childNodeB) - )).toBe(childNodeB); + expect( + ReactMount.getNode( + getNodeID(childNodeB) + ) + ).toBe(childNodeB); + var junkID = getNodeID(childNodeB) + ':junk'; expect(function() { - ReactMount.findComponentRoot( - parentNode, - ReactMount.getID(childNodeB) + ':junk' + ReactMount.getNode( + junkID ); }).toThrow( - 'Invariant Violation: findComponentRoot(..., .0.1:0:junk): ' + + 'Invariant Violation: findComponentRoot(..., ' + junkID + '): ' + 'Unable to find element. This probably means the DOM was ' + 'unexpectedly mutated (e.g., by the browser), usually due to ' + 'forgetting a when using tables, nesting tags ' + 'like
,

, or , or using non-SVG elements in an ' + 'parent. ' + - 'Try inspecting the child nodes of the element with React ID `.0`.' + 'Try inspecting the child nodes of the element with React ID ``.' + ); + + expect(console.error.argsForCall.length).toBe(1); + expect(console.error.argsForCall[0][0]).toContain( + '
cannot appear as a child of
' ); }); });