@@ -444,13 +444,9 @@ describe("Test custom validation v1", () => {
444
444
}
445
445
} ) ;
446
446
447
- let check ;
448
- const fn = jest . fn ( ) ;
449
-
450
-
451
447
it ( "should compile without error" , ( ) => {
452
-
453
- check = v . compile ( {
448
+ const fn = jest . fn ( ) ;
449
+ const check = v . compile ( {
454
450
num : {
455
451
type : "number" ,
456
452
min : 10 ,
@@ -467,6 +463,20 @@ describe("Test custom validation v1", () => {
467
463
} ) ;
468
464
469
465
it ( "should work correctly with custom validator" , ( ) => {
466
+ const fn = jest . fn ( ) ;
467
+ const check = v . compile ( {
468
+ num : {
469
+ type : "number" ,
470
+ min : 10 ,
471
+ max : 15 ,
472
+ integer : true ,
473
+ custom ( value ) {
474
+ fn ( value ) ;
475
+ if ( value % 2 !== 0 ) return [ { type : "evenNumber" , actual : value } ] ;
476
+ }
477
+ }
478
+ } ) ;
479
+
470
480
const res = check ( { num : 12 } ) ;
471
481
expect ( res ) . toBe ( true ) ;
472
482
expect ( fn ) . toBeCalledWith ( 12 ) ;
@@ -475,6 +485,31 @@ describe("Test custom validation v1", () => {
475
485
expect ( check ( { num : 18 } ) [ 0 ] . type ) . toEqual ( "numberMax" ) ;
476
486
expect ( check ( { num : 13 } ) [ 0 ] . type ) . toEqual ( "evenNumber" ) ;
477
487
} ) ;
488
+
489
+ it ( "should work with multiple custom validators" , ( ) => {
490
+ const fn = jest . fn ( ) ;
491
+
492
+ const check = v . compile ( {
493
+ a : {
494
+ type : "number" ,
495
+ custom ( value ) {
496
+ fn ( value ) ;
497
+ if ( value % 2 !== 0 ) return [ { type : "evenNumber" , actual : value } ] ;
498
+ }
499
+ } ,
500
+ b : {
501
+ type : "number" ,
502
+ custom ( value ) {
503
+ fn ( value ) ;
504
+ if ( value % 2 !== 0 ) return [ { type : "evenNumber" , actual : value } ] ;
505
+ }
506
+ }
507
+ } ) ;
508
+
509
+ const res = check ( { a : 12 , b :10 } ) ;
510
+ expect ( res ) . toBe ( true ) ;
511
+ expect ( fn ) . toBeCalledTimes ( 2 ) ;
512
+ } ) ;
478
513
} ) ;
479
514
480
515
describe ( "Test custom validation" , ( ) => {
0 commit comments