@@ -9,6 +9,29 @@ import {
9
9
} from 'react-native' ;
10
10
import { render , getDefaultNormalizer , within } from '../..' ;
11
11
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
+
12
35
type MyButtonProps = {
13
36
children : React . ReactNode ;
14
37
onPress : ( ) => void ;
@@ -192,8 +215,8 @@ test('queryByText not found', () => {
192
215
) . toBeFalsy ( ) ;
193
216
} ) ;
194
217
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 (
197
220
< Text nativeID = "1" >
198
221
Hello{ ' ' }
199
222
< Text nativeID = "2" >
@@ -203,7 +226,7 @@ test('queryByText does not match nested text across multiple <Text> in <Text>',
203
226
</ Text >
204
227
) ;
205
228
206
- expect ( queryByText ( 'Hello World!' ) ) . toBe ( null ) ;
229
+ expect ( getByText ( 'Hello World!' ) ) . toBeTruthy ( ) ;
207
230
} ) ;
208
231
209
232
test ( 'queryByText with nested Text components return the closest Text' , ( ) => {
@@ -214,7 +237,6 @@ test('queryByText with nested Text components return the closest Text', () => {
214
237
) ;
215
238
216
239
const { queryByText } = render ( < NestedTexts /> ) ;
217
-
218
240
expect ( queryByText ( 'My text' , { exact : false } ) ?. props . nativeID ) . toBe ( '2' ) ;
219
241
} ) ;
220
242
@@ -241,8 +263,8 @@ test('queryByText nested deep <CustomText> in <Text>', () => {
241
263
< Text >
242
264
< CustomText > Hello</ CustomText > < CustomText > World!</ CustomText >
243
265
</ Text >
244
- ) . queryByText ( 'Hello World!' )
245
- ) . toBe ( null ) ;
266
+ ) . getByText ( 'Hello World!' )
267
+ ) . toBeTruthy ( ) ;
246
268
} ) ;
247
269
248
270
test ( 'queryByText with nested Text components: not-exact text match returns the most deeply nested common component' , ( ) => {
@@ -365,7 +387,6 @@ describe('Supports normalization', () => {
365
387
< View >
366
388
< Text > { ` Text and
367
389
368
-
369
390
whitespace` } </ Text >
370
391
</ View >
371
392
) ;
@@ -376,7 +397,6 @@ describe('Supports normalization', () => {
376
397
test ( 'trim and collapseWhitespace is customizable by getDefaultNormalizer param' , ( ) => {
377
398
const testTextWithWhitespace = ` Text and
378
399
379
-
380
400
whitespace` ;
381
401
const { getByText } = render (
382
402
< View >
0 commit comments