11import * as React from 'react' ;
22import { Text , TouchableOpacity , View , Pressable } from 'react-native' ;
3- import { fireEvent , render , waitFor } from '..' ;
3+ import { fireEvent , render , waitFor , configure , resetToDefaults } from '..' ;
44
55class Banana extends React . Component < any > {
66 changeFresh = ( ) => {
@@ -19,6 +19,10 @@ class Banana extends React.Component<any> {
1919 }
2020}
2121
22+ beforeEach ( ( ) => {
23+ resetToDefaults ( ) ;
24+ } ) ;
25+
2226class BananaContainer extends React . Component < { } , any > {
2327 state = { fresh : false } ;
2428
@@ -64,6 +68,32 @@ test('waits for element until timeout is met', async () => {
6468 await waitFor ( ( ) => getByText ( 'Fresh' ) ) ;
6569} ) ;
6670
71+ test ( 'waitFor defaults to asyncWaitTimeout config option' , async ( ) => {
72+ configure ( { asyncUtilTimeout : 100 } ) ;
73+ const { getByText } = render ( < BananaContainer /> ) ;
74+
75+ fireEvent . press ( getByText ( 'Change freshness!' ) ) ;
76+ await expect ( waitFor ( ( ) => getByText ( 'Fresh' ) ) ) . rejects . toThrow ( ) ;
77+
78+ // Async action ends after 300ms and we only waited 100ms, so we need to wait
79+ // for the remaining async actions to finish
80+ await waitFor ( ( ) => getByText ( 'Fresh' ) , { timeout : 1000 } ) ;
81+ } ) ;
82+
83+ test ( 'waitFor timeout option takes precendence over `asyncWaitTimeout` config option' , async ( ) => {
84+ configure ( { asyncUtilTimeout : 2000 } ) ;
85+ const { getByText } = render ( < BananaContainer /> ) ;
86+
87+ fireEvent . press ( getByText ( 'Change freshness!' ) ) ;
88+ await expect (
89+ waitFor ( ( ) => getByText ( 'Fresh' ) , { timeout : 100 } )
90+ ) . rejects . toThrow ( ) ;
91+
92+ // Async action ends after 300ms and we only waited 100ms, so we need to wait
93+ // for the remaining async actions to finish
94+ await waitFor ( ( ) => getByText ( 'Fresh' ) ) ;
95+ } ) ;
96+
6797test ( 'waits for element with custom interval' , async ( ) => {
6898 const mockFn = jest . fn ( ( ) => {
6999 throw Error ( 'test' ) ;
0 commit comments