@@ -462,3 +462,53 @@ it('marks fields as valid on precognition success', async () => {
462
462
expect ( validator . valid ( ) ) . toStrictEqual ( [ 'name' ] )
463
463
expect ( valid ) . toStrictEqual ( [ 'name' ] )
464
464
} )
465
+
466
+ it ( 'does not cancel submit requests' , async ( ) => {
467
+ let data = { }
468
+ let submitConfig
469
+ let validateConfig
470
+ axios . request . mockImplementation ( ( config ) => {
471
+ if ( config . precognitive ) {
472
+ validateConfig = config
473
+ } else {
474
+ submitConfig = config
475
+ }
476
+
477
+ return Promise . resolve ( { headers : { precognition : 'true' , 'precognition-success' : 'true' } , status : 204 , data : '' } )
478
+ } )
479
+ const validator = createValidator ( ( client ) => client . post ( '/foo' , data ) )
480
+
481
+ data . name = 'Tim'
482
+ client . post ( '/foo' , data , { precognitive : false } )
483
+ validator . validate ( 'name' , 'Tim' )
484
+
485
+ expect ( submitConfig . signal ) . toBeUndefined ( )
486
+ expect ( validateConfig . signal ) . toBeInstanceOf ( AbortSignal )
487
+ expect ( validateConfig . signal . aborted ) . toBe ( false )
488
+ } ) ;
489
+
490
+ it ( 'does not cancel submit requests with custom abort signal' , async ( ) => {
491
+ let data = { }
492
+ let submitConfig
493
+ let validateConfig
494
+ let abortController = new AbortController
495
+ axios . request . mockImplementation ( ( config ) => {
496
+ if ( config . precognitive ) {
497
+ validateConfig = config
498
+ } else {
499
+ submitConfig = config
500
+ }
501
+
502
+ return Promise . resolve ( { headers : { precognition : 'true' , 'precognition-success' : 'true' } , status : 204 , data : '' } )
503
+ } )
504
+ const validator = createValidator ( ( client ) => client . post ( '/foo' , data ) )
505
+
506
+ data . name = 'Tim'
507
+ client . post ( '/foo' , data , { precognitive : false , signal : abortController . signal } )
508
+ validator . validate ( 'name' , 'Tim' )
509
+
510
+ expect ( submitConfig . signal ) . toBe ( abortController . signal )
511
+ expect ( submitConfig . signal . aborted ) . toBe ( false )
512
+ expect ( validateConfig . signal ) . toBeInstanceOf ( AbortSignal )
513
+ expect ( validateConfig . signal . aborted ) . toBe ( false )
514
+ } ) ;
0 commit comments