@@ -402,6 +402,59 @@ describe('ReactScope', () => {
402402 expect ( node ) . toEqual ( aRef . current ) ;
403403 } ) ;
404404
405+ it ( 'containsNode() works as intended' , ( ) => {
406+ const TestScope = React . unstable_createScope ( ( type , props ) => true ) ;
407+ const scopeRef = React . createRef ( ) ;
408+ const divRef = React . createRef ( ) ;
409+ const spanRef = React . createRef ( ) ;
410+ const aRef = React . createRef ( ) ;
411+ const outerSpan = React . createRef ( ) ;
412+ const emRef = React . createRef ( ) ;
413+
414+ function Test ( { toggle} ) {
415+ return toggle ? (
416+ < div >
417+ < span ref = { outerSpan } > SPAN</ span >
418+ < TestScope ref = { scopeRef } >
419+ < div ref = { divRef } > DIV</ div >
420+ < span ref = { spanRef } > SPAN</ span >
421+ < a ref = { aRef } > A</ a >
422+ </ TestScope >
423+ < em ref = { emRef } > EM</ em >
424+ </ div >
425+ ) : (
426+ < div >
427+ < TestScope ref = { scopeRef } >
428+ < a ref = { aRef } > A</ a >
429+ < div ref = { divRef } > DIV</ div >
430+ < span ref = { spanRef } > SPAN</ span >
431+ < em ref = { emRef } > EM</ em >
432+ </ TestScope >
433+ < span ref = { outerSpan } > SPAN</ span >
434+ </ div >
435+ ) ;
436+ }
437+
438+ const renderer = ReactTestRenderer . create ( < Test toggle = { true } /> , {
439+ createNodeMock : element => {
440+ return element ;
441+ } ,
442+ } ) ;
443+ expect ( scopeRef . current . containsNode ( divRef . current ) ) . toBe ( true ) ;
444+ expect ( scopeRef . current . containsNode ( spanRef . current ) ) . toBe ( true ) ;
445+ expect ( scopeRef . current . containsNode ( aRef . current ) ) . toBe ( true ) ;
446+ expect ( scopeRef . current . containsNode ( outerSpan . current ) ) . toBe ( false ) ;
447+ expect ( scopeRef . current . containsNode ( emRef . current ) ) . toBe ( false ) ;
448+ renderer . update ( < Test toggle = { false } /> ) ;
449+ expect ( scopeRef . current . containsNode ( divRef . current ) ) . toBe ( true ) ;
450+ expect ( scopeRef . current . containsNode ( spanRef . current ) ) . toBe ( true ) ;
451+ expect ( scopeRef . current . containsNode ( aRef . current ) ) . toBe ( true ) ;
452+ expect ( scopeRef . current . containsNode ( outerSpan . current ) ) . toBe ( false ) ;
453+ expect ( scopeRef . current . containsNode ( emRef . current ) ) . toBe ( true ) ;
454+ renderer . update ( < Test toggle = { true } /> ) ;
455+ expect ( scopeRef . current . containsNode ( emRef . current ) ) . toBe ( false ) ;
456+ } ) ;
457+
405458 it ( 'mixed getParent() and getAllNodes() works as intended' , ( ) => {
406459 const TestScope = React . unstable_createScope ( ( type , props ) => true ) ;
407460 const TestScope2 = React . unstable_createScope ( ( type , props ) => true ) ;
0 commit comments