1414 * limitations under the License.
1515 */
1616
17- import { act , render , renderHook , screen } from '@testing-library/react' ;
17+ import { act , render , renderHook , screen , waitFor } from '@testing-library/react' ;
1818import React from 'react' ;
1919import * as yup from 'yup' ;
2020import RruDateTimeInput from '../../form/RruDateTimeInput/RruDateTimeInput' ;
@@ -177,8 +177,10 @@ describe('RruDateTimeInput', () => {
177177 await submitForm ( container ) ;
178178
179179 // validation for bad input
180- expect ( onSubmit ) . toHaveBeenCalledTimes ( 0 ) ;
181- expect ( screen . getByText ( 'The date is too old' ) ) . toBeTruthy ( ) ;
180+ await waitFor ( ( ) => {
181+ expect ( onSubmit ) . toHaveBeenCalledTimes ( 0 ) ;
182+ expect ( screen . getByText ( 'The date is too old' ) ) . toBeTruthy ( ) ;
183+ } ) ;
182184
183185 // delete the current value in the input element
184186 await selectDate ( container , 'birthDate' , '2020-05-12' ) ;
@@ -187,11 +189,13 @@ describe('RruDateTimeInput', () => {
187189 await submitForm ( container ) ;
188190
189191 // validation for valid input
190- expect ( onSubmit ) . toHaveBeenCalledTimes ( 1 ) ;
191- expect ( onSubmit . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
192- // because using YUP validation schema causes the value to be casted to Date object
193- // TODO: This is a bug in react-hook-form, open PR
194- birthDate : new Date ( new Date ( '2020-05-12' ) . getTime ( ) - 3 * 60 * 60 * 1000 ) ,
192+ await waitFor ( ( ) => {
193+ expect ( onSubmit ) . toHaveBeenCalledTimes ( 1 ) ;
194+ expect ( onSubmit . mock . calls [ 0 ] [ 0 ] ) . toEqual ( {
195+ // because using YUP validation schema causes the value to be casted to Date object
196+ // TODO: This is a bug in react-hook-form, open PR
197+ birthDate : new Date ( new Date ( '2020-05-12' ) . getTime ( ) - 3 * 60 * 60 * 1000 ) ,
198+ } ) ;
195199 } ) ;
196200 } ) ;
197201
0 commit comments