File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -3549,6 +3549,24 @@ describe('Query', function() {
3549
3549
assert . equal ( doc . password , 'encryptedpassword' ) ;
3550
3550
} ) ;
3551
3551
} ) ;
3552
+
3553
+ it ( 'pre("validate") errors (gh-7187)' , function ( ) {
3554
+ const addressSchema = Schema ( { countryId : String } ) ;
3555
+ addressSchema . pre ( 'validate' , { query : true } , function ( ) {
3556
+ throw new Error ( 'Oops!' ) ;
3557
+ } ) ;
3558
+ const contactSchema = Schema ( { addresses : [ addressSchema ] } ) ;
3559
+ const Contact = db . model ( 'gh7187' , contactSchema ) ;
3560
+
3561
+ const update = { addresses : [ { countryId : 'foo' } ] } ;
3562
+ return Contact . updateOne ( { } , update , { runValidators : true } ) . then (
3563
+ ( ) => assert . ok ( false ) ,
3564
+ err => {
3565
+ assert . ok ( err . errors [ 'addresses.0' ] ) ;
3566
+ assert . equal ( err . errors [ 'addresses.0' ] . message , 'Oops!' ) ;
3567
+ }
3568
+ ) ;
3569
+ } ) ;
3552
3570
} ) ;
3553
3571
3554
3572
it ( 'query with top-level _bsontype (gh-8222)' , function ( ) {
You can’t perform that action at this time.
0 commit comments