@@ -9,6 +9,29 @@ import {
99} from 'react-native' ;
1010import { render , getDefaultNormalizer , within } from '../..' ;
1111
12+ test ( 'byText matches simple text' , ( ) => {
13+ const { getByText } = render ( < Text testID = "text" > Hello World</ Text > ) ;
14+ expect ( getByText ( 'Hello World' ) . props . testID ) . toBe ( 'text' ) ;
15+ } ) ;
16+
17+ test ( 'byText matches inner nested text' , ( ) => {
18+ const { getByText } = render (
19+ < Text testID = "outer" >
20+ < Text testID = "inner" > Hello World</ Text >
21+ </ Text >
22+ ) ;
23+ expect ( getByText ( 'Hello World' ) . props . testID ) . toBe ( 'inner' ) ;
24+ } ) ;
25+
26+ test ( 'byText matches accross multiple texts' , ( ) => {
27+ const { getByText } = render (
28+ < Text testID = "outer" >
29+ < Text testID = "inner-1" > Hello</ Text > < Text testID = "inner-2" > World</ Text >
30+ </ Text >
31+ ) ;
32+ expect ( getByText ( 'Hello World' ) . props . testID ) . toBe ( 'outer' ) ;
33+ } ) ;
34+
1235type MyButtonProps = {
1336 children : React . ReactNode ;
1437 onPress : ( ) => void ;
@@ -192,8 +215,8 @@ test('queryByText not found', () => {
192215 ) . toBeFalsy ( ) ;
193216} ) ;
194217
195- test ( 'queryByText does not match nested text across multiple <Text> in < Text> ' , ( ) => {
196- const { queryByText } = render (
218+ test ( '*ByText matches text across multiple nested Text' , ( ) => {
219+ const { getByText } = render (
197220 < Text nativeID = "1" >
198221 Hello{ ' ' }
199222 < Text nativeID = "2" >
@@ -203,7 +226,7 @@ test('queryByText does not match nested text across multiple <Text> in <Text>',
203226 </ Text >
204227 ) ;
205228
206- expect ( queryByText ( 'Hello World!' ) ) . toBe ( null ) ;
229+ expect ( getByText ( 'Hello World!' ) ) . toBeTruthy ( ) ;
207230} ) ;
208231
209232test ( 'queryByText with nested Text components return the closest Text' , ( ) => {
@@ -214,7 +237,6 @@ test('queryByText with nested Text components return the closest Text', () => {
214237 ) ;
215238
216239 const { queryByText } = render ( < NestedTexts /> ) ;
217-
218240 expect ( queryByText ( 'My text' , { exact : false } ) ?. props . nativeID ) . toBe ( '2' ) ;
219241} ) ;
220242
@@ -241,8 +263,8 @@ test('queryByText nested deep <CustomText> in <Text>', () => {
241263 < Text >
242264 < CustomText > Hello</ CustomText > < CustomText > World!</ CustomText >
243265 </ Text >
244- ) . queryByText ( 'Hello World!' )
245- ) . toBe ( null ) ;
266+ ) . getByText ( 'Hello World!' )
267+ ) . toBeTruthy ( ) ;
246268} ) ;
247269
248270test ( 'queryByText with nested Text components: not-exact text match returns the most deeply nested common component' , ( ) => {
@@ -365,7 +387,6 @@ describe('Supports normalization', () => {
365387 < View >
366388 < Text > { ` Text and
367389
368-
369390 whitespace` } </ Text >
370391 </ View >
371392 ) ;
@@ -376,7 +397,6 @@ describe('Supports normalization', () => {
376397 test ( 'trim and collapseWhitespace is customizable by getDefaultNormalizer param' , ( ) => {
377398 const testTextWithWhitespace = ` Text and
378399
379-
380400 whitespace` ;
381401 const { getByText } = render (
382402 < View >
0 commit comments