11import React from 'react' ;
2- import { Text , TextInput , View } from 'react-native' ;
2+ import { View } from 'react-native' ;
33import { render , screen } from '../..' ;
4- import {
5- getHostChildren ,
6- getHostSelves ,
7- getHostSiblings ,
8- getUnsafeRootElement ,
9- } from '../component-tree' ;
4+ import { getHostSiblings , getUnsafeRootElement } from '../component-tree' ;
105
116function MultipleHostChildren ( ) {
127 return (
@@ -18,98 +13,6 @@ function MultipleHostChildren() {
1813 ) ;
1914}
2015
21- describe ( 'getHostChildren()' , ( ) => {
22- it ( 'returns host children for host component' , ( ) => {
23- render (
24- < View testID = "grandparent" >
25- < View testID = "parent" >
26- < View testID = "subject" />
27- < Text testID = "sibling" > Hello</ Text >
28- </ View >
29- </ View > ,
30- ) ;
31-
32- const hostSubject = screen . getByTestId ( 'subject' ) ;
33- expect ( getHostChildren ( hostSubject ) ) . toEqual ( [ ] ) ;
34-
35- const hostSibling = screen . getByTestId ( 'sibling' ) ;
36- expect ( getHostChildren ( hostSibling ) ) . toEqual ( [ ] ) ;
37-
38- const hostParent = screen . getByTestId ( 'parent' ) ;
39- expect ( getHostChildren ( hostParent ) ) . toEqual ( [ hostSubject , hostSibling ] ) ;
40-
41- const hostGrandparent = screen . getByTestId ( 'grandparent' ) ;
42- expect ( getHostChildren ( hostGrandparent ) ) . toEqual ( [ hostParent ] ) ;
43- } ) ;
44-
45- it ( 'returns host children for composite component' , ( ) => {
46- render (
47- < View testID = "parent" >
48- < MultipleHostChildren />
49- < View testID = "subject" />
50- < View testID = "sibling" />
51- </ View > ,
52- ) ;
53-
54- expect ( getHostChildren ( screen . getByTestId ( 'parent' ) ) ) . toEqual ( [
55- screen . getByTestId ( 'child1' ) ,
56- screen . getByTestId ( 'child2' ) ,
57- screen . getByTestId ( 'child3' ) ,
58- screen . getByTestId ( 'subject' ) ,
59- screen . getByTestId ( 'sibling' ) ,
60- ] ) ;
61- } ) ;
62- } ) ;
63-
64- describe ( 'getHostSelves()' , ( ) => {
65- it ( 'returns passed element for host components' , ( ) => {
66- render (
67- < View testID = "grandparent" >
68- < View testID = "parent" >
69- < View testID = "subject" />
70- < View testID = "sibling" />
71- </ View >
72- </ View > ,
73- ) ;
74-
75- const hostSubject = screen . getByTestId ( 'subject' ) ;
76- expect ( getHostSelves ( hostSubject ) ) . toEqual ( [ hostSubject ] ) ;
77-
78- const hostSibling = screen . getByTestId ( 'sibling' ) ;
79- expect ( getHostSelves ( hostSibling ) ) . toEqual ( [ hostSibling ] ) ;
80-
81- const hostParent = screen . getByTestId ( 'parent' ) ;
82- expect ( getHostSelves ( hostParent ) ) . toEqual ( [ hostParent ] ) ;
83-
84- const hostGrandparent = screen . getByTestId ( 'grandparent' ) ;
85- expect ( getHostSelves ( hostGrandparent ) ) . toEqual ( [ hostGrandparent ] ) ;
86- } ) ;
87-
88- test ( 'returns single host element for React Native composite components' , ( ) => {
89- render (
90- < View testID = "parent" >
91- < Text testID = "text" > Text</ Text >
92- < TextInput
93- testID = "textInput"
94- defaultValue = "TextInputValue"
95- placeholder = "TextInputPlaceholder"
96- />
97- </ View > ,
98- ) ;
99-
100- const compositeText = screen . getByText ( 'Text' ) ;
101- const hostText = screen . getByTestId ( 'text' ) ;
102- expect ( getHostSelves ( compositeText ) ) . toEqual ( [ hostText ] ) ;
103-
104- const compositeTextInputByValue = screen . getByDisplayValue ( 'TextInputValue' ) ;
105- const compositeTextInputByPlaceholder = screen . getByPlaceholderText ( 'TextInputPlaceholder' ) ;
106-
107- const hostTextInput = screen . getByTestId ( 'textInput' ) ;
108- expect ( getHostSelves ( compositeTextInputByValue ) ) . toEqual ( [ hostTextInput ] ) ;
109- expect ( getHostSelves ( compositeTextInputByPlaceholder ) ) . toEqual ( [ hostTextInput ] ) ;
110- } ) ;
111- } ) ;
112-
11316describe ( 'getHostSiblings()' , ( ) => {
11417 it ( 'returns host siblings for host component' , ( ) => {
11518 render (
0 commit comments