File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -3549,6 +3549,24 @@ describe('Query', function() {
35493549 assert . equal ( doc . password , 'encryptedpassword' ) ;
35503550 } ) ;
35513551 } ) ;
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+ } ) ;
35523570 } ) ;
35533571
35543572 it ( 'query with top-level _bsontype (gh-8222)' , function ( ) {
You can’t perform that action at this time.
0 commit comments