@@ -36,7 +36,7 @@ function getChildren(node) {
3636 if ( typeof child === 'string' ) {
3737 return child ;
3838 } else if ( validComponentFilter ( child ) ) {
39- return proxyUnsafeProperties ( child ) ;
39+ return proxyElement ( child ) ;
4040 }
4141
4242 return getChildren ( child ) ;
@@ -45,15 +45,13 @@ function getChildren(node) {
4545
4646function getParent ( node ) {
4747 if ( node . parent ) {
48- return validComponentFilter ( node . parent )
49- ? proxyUnsafeProperties ( node . parent )
50- : getParent ( node . parent ) ;
48+ return validComponentFilter ( node . parent ) ? proxyElement ( node . parent ) : getParent ( node . parent ) ;
5149 }
5250
5351 return null ;
5452}
5553
56- function proxyUnsafeProperties ( node ) {
54+ function proxyElement ( node ) {
5755 // We take the guiding principles seriously around these parts. These methods just let
5856 // you do too much unfortunately, and they make it hard to follow the rules of the
5957 // testing-library. It's not that we don't trust you, in fact we do trust you! We've
@@ -69,19 +67,16 @@ function proxyUnsafeProperties(node) {
6967 // need using the query methods provided on the `render` API.
7068 return new Proxy ( node , {
7169 get ( target , key ) {
70+ const ref = target [ key ] ;
71+
7272 switch ( key ) {
7373 case 'findAll' :
74- const ref = target [ key ] ;
7574 return function ( cb ) {
76- const overrideCb = n => cb ( proxyUnsafeProperties ( n ) ) ;
77- return ref
78- . apply ( this , [ overrideCb ] )
79- . filter ( node => validComponentFilter ( node ) )
80- . map ( proxyUnsafeProperties ) ;
75+ const overrideCb = n => cb ( proxyElement ( n ) ) ;
76+ return ref . apply ( this , [ overrideCb ] ) ;
8177 } ;
8278 case 'getProp' :
8379 return function ( prop ) {
84- /* istanbul ignore next */
8580 return target . props [ prop ] ;
8681 } ;
8782 case 'children' :
@@ -90,6 +85,7 @@ function proxyUnsafeProperties(node) {
9085 return getParent ( target ) ;
9186 case '$$typeof' :
9287 return Symbol . for ( 'ntl.element' ) ;
88+ case 'find' :
9389 case 'findAllByProps' :
9490 case 'findAllByType' :
9591 case 'findByProps' :
@@ -98,7 +94,7 @@ function proxyUnsafeProperties(node) {
9894 return undefined ;
9995 default :
10096 // Let things behave normally if you're not running a query
101- return target [ key ] ;
97+ return ref ;
10298 }
10399 } ,
104100 } ) ;
@@ -178,6 +174,6 @@ export {
178174 makeSingleQuery ,
179175 queryAllByProp ,
180176 queryByProp ,
181- proxyUnsafeProperties ,
177+ proxyElement ,
182178 validComponentFilter ,
183179} ;
0 commit comments