@@ -4,11 +4,8 @@ import { render } from '../..';
44import {
55 getHostChildren ,
66 getHostParent ,
7- getHostSelf ,
87 getHostSelves ,
98 getHostSiblings ,
10- getCompositeParentOfType ,
11- isHostElementForType ,
129} from '../component-tree' ;
1310
1411function ZeroHostChildren ( ) {
@@ -106,72 +103,6 @@ describe('getHostChildren()', () => {
106103 } ) ;
107104} ) ;
108105
109- describe ( 'getHostSelf()' , ( ) => {
110- it ( 'returns passed element for host components' , ( ) => {
111- const view = render (
112- < View testID = "grandparent" >
113- < View testID = "parent" >
114- < View testID = "subject" />
115- < View testID = "sibling" />
116- </ View >
117- </ View >
118- ) ;
119-
120- const hostSubject = view . getByTestId ( 'subject' ) ;
121- expect ( getHostSelf ( hostSubject ) ) . toEqual ( hostSubject ) ;
122-
123- const hostSibling = view . getByTestId ( 'sibling' ) ;
124- expect ( getHostSelf ( hostSibling ) ) . toEqual ( hostSibling ) ;
125-
126- const hostParent = view . getByTestId ( 'parent' ) ;
127- expect ( getHostSelf ( hostParent ) ) . toEqual ( hostParent ) ;
128-
129- const hostGrandparent = view . getByTestId ( 'grandparent' ) ;
130- expect ( getHostSelf ( hostGrandparent ) ) . toEqual ( hostGrandparent ) ;
131- } ) ;
132-
133- it ( 'returns single host child for React Native composite components' , ( ) => {
134- const view = render (
135- < View testID = "parent" >
136- < Text testID = "text" > Text</ Text >
137- < TextInput
138- testID = "textInput"
139- defaultValue = "TextInputValue"
140- placeholder = "TextInputPlaceholder"
141- />
142- </ View >
143- ) ;
144-
145- const compositeText = view . UNSAFE_getByType ( Text ) ;
146- const hostText = view . getByTestId ( 'text' ) ;
147- expect ( getHostSelf ( compositeText ) ) . toEqual ( hostText ) ;
148-
149- const compositeTextInput = view . UNSAFE_getByType ( TextInput ) ;
150- const hostTextInput = view . getByTestId ( 'textInput' ) ;
151- expect ( getHostSelf ( compositeTextInput ) ) . toEqual ( hostTextInput ) ;
152- } ) ;
153-
154- it ( 'throws on non-single host children elements for custom composite components' , ( ) => {
155- const view = render (
156- < View testID = "parent" >
157- < ZeroHostChildren />
158- < MultipleHostChildren />
159- </ View >
160- ) ;
161-
162- const zeroCompositeComponent = view . UNSAFE_getByType ( ZeroHostChildren ) ;
163- expect ( ( ) => getHostSelf ( zeroCompositeComponent ) ) . toThrow (
164- 'Expected exactly one host element, but found none.'
165- ) ;
166-
167- const multipleCompositeComponent =
168- view . UNSAFE_getByType ( MultipleHostChildren ) ;
169- expect ( ( ) => getHostSelf ( multipleCompositeComponent ) ) . toThrow (
170- 'Expected exactly one host element, but found 3.'
171- ) ;
172- } ) ;
173- } ) ;
174-
175106describe ( 'getHostSelves()' , ( ) => {
176107 it ( 'returns passed element for host components' , ( ) => {
177108 const view = render (
@@ -293,38 +224,3 @@ describe('getHostSiblings()', () => {
293224 ] ) ;
294225 } ) ;
295226} ) ;
296-
297- test ( 'getCompositeParentOfType' , ( ) => {
298- const root = render (
299- < View testID = "view" >
300- < Text testID = "text" />
301- </ View >
302- ) ;
303- const hostView = root . getByTestId ( 'view' ) ;
304- const hostText = root . getByTestId ( 'text' ) ;
305-
306- const compositeView = getCompositeParentOfType ( hostView , View ) ;
307- // We get the corresponding composite component (same testID), but not the host
308- expect ( compositeView ?. type ) . toBe ( View ) ;
309- expect ( compositeView ?. props . testID ) . toBe ( 'view' ) ;
310- const compositeText = getCompositeParentOfType ( hostText , Text ) ;
311- expect ( compositeText ?. type ) . toBe ( Text ) ;
312- expect ( compositeText ?. props . testID ) . toBe ( 'text' ) ;
313-
314- // Checks parent type
315- expect ( getCompositeParentOfType ( hostText , View ) ) . toBeNull ( ) ;
316- expect ( getCompositeParentOfType ( hostView , Text ) ) . toBeNull ( ) ;
317-
318- // Ignores itself, stops if ancestor is host
319- expect ( getCompositeParentOfType ( compositeText ! , Text ) ) . toBeNull ( ) ;
320- expect ( getCompositeParentOfType ( compositeView ! , View ) ) . toBeNull ( ) ;
321- } ) ;
322-
323- test ( 'isHostElementForType' , ( ) => {
324- const view = render ( < View testID = "test" /> ) ;
325- const hostComponent = view . getByTestId ( 'test' ) ;
326- const compositeComponent = getCompositeParentOfType ( hostComponent , View ) ;
327- expect ( isHostElementForType ( hostComponent , View ) ) . toBe ( true ) ;
328- expect ( isHostElementForType ( hostComponent , Text ) ) . toBe ( false ) ;
329- expect ( isHostElementForType ( compositeComponent ! , View ) ) . toBe ( false ) ;
330- } ) ;
0 commit comments