@@ -31,6 +31,7 @@ const RENDERER = sym('__renderer__');
3131const UNRENDERED = sym ( '__unrendered__' ) ;
3232const ROOT = sym ( '__root__' ) ;
3333const OPTIONS = sym ( '__options__' ) ;
34+ const ROOT_NODES = sym ( '__rootNodes__' ) ;
3435
3536/**
3637 * Finds all nodes in the current wrapper nodes' render trees that match the provided predicate
@@ -57,8 +58,18 @@ function filterWhereUnwrapped(wrapper, predicate) {
5758 return wrapper . wrap ( wrapper . getNodesInternal ( ) . filter ( predicate ) . filter ( Boolean ) ) ;
5859}
5960
61+ function getRootNodeInternal ( wrapper ) {
62+ if ( wrapper [ ROOT ] . length !== 1 ) {
63+ throw new Error ( 'getRootNodeInternal(wrapper) can only be called when wrapper wraps one node' ) ;
64+ }
65+ if ( wrapper [ ROOT ] !== wrapper ) {
66+ return wrapper [ ROOT_NODES ] [ 0 ] ;
67+ }
68+ return wrapper [ ROOT ] [ NODE ] ;
69+ }
70+
6071function nodeParents ( wrapper , node ) {
61- return parentsOfNode ( node , wrapper [ ROOT ] . getNodeInternal ( ) ) ;
72+ return parentsOfNode ( node , getRootNodeInternal ( wrapper ) ) ;
6273}
6374
6475function privateSetNodes ( wrapper , nodes ) {
@@ -102,6 +113,7 @@ class ReactWrapper {
102113 privateSet ( this , RENDERER , root [ RENDERER ] ) ;
103114 privateSet ( this , ROOT , root ) ;
104115 privateSetNodes ( this , nodes ) ;
116+ privateSet ( this , ROOT_NODES , root [ NODES ] ) ;
105117 }
106118 privateSet ( this , OPTIONS , root ? root [ OPTIONS ] : options ) ;
107119 }
@@ -639,7 +651,7 @@ class ReactWrapper {
639651 throw new TypeError ( 'your adapter does not support `simulateError`. Try upgrading it!' ) ;
640652 }
641653
642- const rootNode = this [ ROOT ] . getNodeInternal ( ) ;
654+ const rootNode = getRootNodeInternal ( this ) ;
643655 const nodeHierarchy = [ thisNode ] . concat ( nodeParents ( this , thisNode ) ) ;
644656 renderer . simulateError ( nodeHierarchy , rootNode , error ) ;
645657
@@ -737,8 +749,10 @@ class ReactWrapper {
737749 * @returns {ReactWrapper }
738750 */
739751 parents ( selector ) {
740- const allParents = this . wrap ( this . single ( 'parents' , n => nodeParents ( this , n ) ) ) ;
741- return selector ? allParents . filter ( selector ) : allParents ;
752+ return this . single ( 'parents' , ( n ) => {
753+ const allParents = this . wrap ( nodeParents ( this , n ) ) ;
754+ return selector ? allParents . filter ( selector ) : allParents ;
755+ } ) ;
742756 }
743757
744758 /**
0 commit comments