@@ -348,7 +348,7 @@ describe("Field.validation", () => {
348348 } ) ;
349349
350350 it ( "should allow record-level async validation via promises" , async ( ) => {
351- const delay = 2 ;
351+ const delay = 10 ;
352352 const form = createForm ( {
353353 onSubmit : onSubmitMock ,
354354 validate : async ( values ) => {
@@ -393,19 +393,20 @@ describe("Field.validation", () => {
393393
394394 change ( "another" ) ;
395395
396- // spy called because sync validation passed
397- expect ( spy ) . toHaveBeenCalledTimes ( 3 ) ;
398- expect ( spy . mock . calls [ 2 ] [ 0 ] . error ) . toBeUndefined ( ) ;
396+ await sleep ( delay / 2 ) ;
397+
398+ // spy not called because async validation not yet done
399+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
399400
400- // wait for validation to return
401401 await sleep ( delay * 2 ) ;
402402
403- // spy not called because sync validation already cleared error
403+ // spy called because async validation completed
404404 expect ( spy ) . toHaveBeenCalledTimes ( 3 ) ;
405+ expect ( spy . mock . calls [ 2 ] [ 0 ] . error ) . toBeUndefined ( ) ;
405406 } ) ;
406407
407- it . only ( "should not reset record-level async validation results until they have been replaced" , async ( ) => {
408- const delay = 50 ;
408+ it ( "should not reset record-level async validation results until they have been replaced" , async ( ) => {
409+ const delay = 10 ;
409410 const form = createForm ( {
410411 onSubmit : onSubmitMock ,
411412 validate : async ( values ) => {
@@ -441,6 +442,8 @@ describe("Field.validation", () => {
441442 expect ( spy . mock . calls [ 1 ] [ 0 ] . error ) . toBe ( "Username taken" ) ;
442443
443444 change ( "erikrasm" ) ; // too long
445+ change ( "erikrasmu" ) ; // too long
446+ change ( "erikrasmus" ) ; // too long
444447
445448 await sleep ( delay / 2 ) ;
446449
@@ -464,7 +467,7 @@ describe("Field.validation", () => {
464467 // wait for validation to return
465468 await sleep ( delay * 2 ) ;
466469
467- // spy called because sync validation passed
470+ // spy called because async validation passed
468471 expect ( spy ) . toHaveBeenCalledTimes ( 4 ) ;
469472 expect ( spy . mock . calls [ 3 ] [ 0 ] . error ) . toBeUndefined ( ) ;
470473
0 commit comments