1
1
// @flow
2
2
import * as React from 'react' ;
3
- import { TouchableOpacity , Text } from 'react-native' ;
3
+ import { TouchableOpacity , Text , View } from 'react-native' ;
4
4
import { render } from '..' ;
5
5
6
6
const BUTTON_LABEL = 'cool button' ;
@@ -110,10 +110,10 @@ test('getByA11yLabel, queryByA11yLabel, findByA11yLabel', async () => {
110
110
const asyncButton = await findByA11yLabel ( BUTTON_LABEL ) ;
111
111
expect ( asyncButton . props . accessibilityLabel ) . toEqual ( BUTTON_LABEL ) ;
112
112
await expect (
113
- findByA11yLabel ( NO_MATCHES_TEXT , waitForOptions )
113
+ findByA11yLabel ( NO_MATCHES_TEXT , { } , waitForOptions )
114
114
) . rejects . toThrow ( getNoInstancesFoundMessage ( 'accessibilityLabel' ) ) ;
115
115
116
- await expect ( findByA11yLabel ( TEXT_LABEL , waitForOptions ) ) . rejects . toThrow (
116
+ await expect ( findByA11yLabel ( TEXT_LABEL , { } , waitForOptions ) ) . rejects . toThrow (
117
117
FOUND_TWO_INSTANCES
118
118
) ;
119
119
} ) ;
@@ -158,10 +158,10 @@ test('getByA11yHint, queryByA11yHint, findByA11yHint', async () => {
158
158
159
159
const asyncButton = await findByA11yHint ( BUTTON_HINT ) ;
160
160
expect ( asyncButton . props . accessibilityHint ) . toEqual ( BUTTON_HINT ) ;
161
- await expect ( findByA11yHint ( NO_MATCHES_TEXT , waitForOptions ) ) . rejects . toThrow (
162
- getNoInstancesFoundMessage ( 'accessibilityHint' )
163
- ) ;
164
- await expect ( findByA11yHint ( TEXT_HINT , waitForOptions ) ) . rejects . toThrow (
161
+ await expect (
162
+ findByA11yHint ( NO_MATCHES_TEXT , { } , waitForOptions )
163
+ ) . rejects . toThrow ( getNoInstancesFoundMessage ( 'accessibilityHint' ) ) ;
164
+ await expect ( findByA11yHint ( TEXT_HINT , { } , waitForOptions ) ) . rejects . toThrow (
165
165
FOUND_TWO_INSTANCES
166
166
) ;
167
167
} ) ;
@@ -229,7 +229,7 @@ test('getByA11yRole, queryByA11yRole, findByA11yRole with name', async () => {
229
229
name : ONE_OCCURANCE ,
230
230
} ) ;
231
231
await expect (
232
- findByA11yRole ( 'button' , { ... waitForOptions , name : NO_MATCHES_TEXT } )
232
+ findByA11yRole ( 'button' , { name : NO_MATCHES_TEXT } , waitForOptions )
233
233
) . rejects . toThrow ( getNoInstancesFoundMessage ( 'accessibilityRole' , 'button' ) ) ;
234
234
await expect (
235
235
findByA11yRole ( 'button' , {
@@ -257,6 +257,39 @@ test('getAllByA11yRole, queryAllByA11yRole, findAllByA11yRole', async () => {
257
257
) . rejects . toThrow ( getNoInstancesFoundMessage ( 'accessibilityRole' ) ) ;
258
258
} ) ;
259
259
260
+ describe ( 'findBy options deprecations' , ( ) => {
261
+ let warnSpy ;
262
+ beforeEach ( ( ) => {
263
+ warnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
264
+ } ) ;
265
+ afterEach ( ( ) => {
266
+ warnSpy . mockRestore ( ) ;
267
+ } ) ;
268
+
269
+ test ( 'findByText queries warn on deprecated use of WaitForOptions' , async ( ) => {
270
+ const options = { timeout : 10 } ;
271
+ // mock implementation to avoid warning in the test suite
272
+ const { rerender, findByText } = render ( < View /> ) ;
273
+ await expect ( findByText ( 'Some Text' , options ) ) . rejects . toBeTruthy ( ) ;
274
+
275
+ setTimeout (
276
+ ( ) =>
277
+ rerender (
278
+ < View >
279
+ < Text > Some Text</ Text >
280
+ </ View >
281
+ ) ,
282
+ 20
283
+ ) ;
284
+
285
+ await expect ( findByText ( 'Some Text' ) ) . resolves . toBeTruthy ( ) ;
286
+
287
+ expect ( warnSpy ) . toHaveBeenCalledWith (
288
+ expect . stringContaining ( 'Use of option "timeout"' )
289
+ ) ;
290
+ } , 20000 ) ;
291
+ } ) ;
292
+
260
293
test ( 'getAllByA11yRole, queryAllByA11yRole, findAllByA11yRole with name' , async ( ) => {
261
294
const { getAllByA11yRole, queryAllByA11yRole, findAllByA11yRole } = render (
262
295
< ButtonsWithText />
@@ -358,7 +391,7 @@ test('getByA11yState, queryByA11yState, findByA11yState', async () => {
358
391
expanded : false ,
359
392
} ) ;
360
393
await expect (
361
- findByA11yState ( { disabled : true } , waitForOptions )
394
+ findByA11yState ( { disabled : true } , { } , waitForOptions )
362
395
) . rejects . toThrow (
363
396
getNoInstancesFoundMessage (
364
397
'accessibilityState' ,
@@ -367,7 +400,7 @@ test('getByA11yState, queryByA11yState, findByA11yState', async () => {
367
400
)
368
401
) ;
369
402
await expect (
370
- findByA11yState ( { expanded : false } , waitForOptions )
403
+ findByA11yState ( { expanded : false } , { } , waitForOptions )
371
404
) . rejects . toThrow ( FOUND_TWO_INSTANCES ) ;
372
405
} ) ;
373
406
@@ -393,7 +426,7 @@ test('getAllByA11yState, queryAllByA11yState, findAllByA11yState', async () => {
393
426
394
427
await expect ( findAllByA11yState ( { selected : true } ) ) . resolves . toHaveLength ( 1 ) ;
395
428
await expect (
396
- findAllByA11yState ( { disabled : true } , waitForOptions )
429
+ findAllByA11yState ( { disabled : true } , { } , waitForOptions )
397
430
) . rejects . toThrow (
398
431
getNoInstancesFoundMessage (
399
432
'accessibilityState' ,
@@ -433,12 +466,14 @@ test('getByA11yValue, queryByA11yValue, findByA11yValue', async () => {
433
466
min : 40 ,
434
467
max : 60 ,
435
468
} ) ;
436
- await expect ( findByA11yValue ( { min : 50 } , waitForOptions ) ) . rejects . toThrow (
469
+ await expect (
470
+ findByA11yValue ( { min : 50 } , { } , waitForOptions )
471
+ ) . rejects . toThrow (
437
472
getNoInstancesFoundMessage ( 'accessibilityValue' , '{"min": 50}' , false )
438
473
) ;
439
- await expect ( findByA11yValue ( { max : 60 } , waitForOptions ) ) . rejects . toThrow (
440
- FOUND_TWO_INSTANCES
441
- ) ;
474
+ await expect (
475
+ findByA11yValue ( { max : 60 } , { } , waitForOptions )
476
+ ) . rejects . toThrow ( FOUND_TWO_INSTANCES ) ;
442
477
} ) ;
443
478
444
479
test ( 'getAllByA11yValue, queryAllByA11yValue, findAllByA11yValue' , async ( ) => {
@@ -458,7 +493,9 @@ test('getAllByA11yValue, queryAllByA11yValue, findAllByA11yValue', async () => {
458
493
expect ( getAllByA11yValue ( { max : 60 } ) ) . toHaveLength ( 2 ) ;
459
494
460
495
await expect ( findAllByA11yValue ( { min : 40 } ) ) . resolves . toHaveLength ( 1 ) ;
461
- await expect ( findAllByA11yValue ( { min : 50 } , waitForOptions ) ) . rejects . toThrow (
496
+ await expect (
497
+ findAllByA11yValue ( { min : 50 } , { } , waitForOptions )
498
+ ) . rejects . toThrow (
462
499
getNoInstancesFoundMessage ( 'accessibilityValue' , '{"min": 50}' , false )
463
500
) ;
464
501
await expect ( findAllByA11yValue ( { max : 60 } ) ) . resolves . toHaveLength ( 2 ) ;
0 commit comments