File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -12493,6 +12493,29 @@ describe('document', function() {
12493
12493
assert . strictEqual ( parent . get ( 'child.concreteProp' ) , 123 ) ;
12494
12494
assert . strictEqual ( parent . toObject ( ) . child . concreteProp , 123 ) ;
12495
12495
} ) ;
12496
+
12497
+ it ( 'avoids saving changes to deselected paths (gh-13145) (gh-13062)' , async function ( ) {
12498
+ const testSchema = new mongoose . Schema ( {
12499
+ name : { type : String , required : true } ,
12500
+ age : { type : Number , required : true , select : false } ,
12501
+ links : { type : String , required : true , select : false }
12502
+ } ) ;
12503
+
12504
+ const Test = db . model ( 'Test' , testSchema ) ;
12505
+
12506
+ const { _id } = await Test . create ( {
12507
+ name : 'Test Testerson' ,
12508
+ age : 0 ,
12509
+ links : 'some init links'
12510
+ } ) ;
12511
+
12512
+ const doc = await Test . findById ( _id ) ;
12513
+ doc . links = undefined ;
12514
+ const err = await doc . save ( ) . then ( ( ) => null , err => err ) ;
12515
+ assert . ok ( err ) ;
12516
+ assert . ok ( err . errors [ 'links' ] ) ;
12517
+ assert . equal ( err . errors [ 'links' ] . message , 'Path `links` is required.' ) ;
12518
+ } ) ;
12496
12519
} ) ;
12497
12520
12498
12521
describe ( 'Check if instance function that is supplied in schema option is availabe' , function ( ) {
You can’t perform that action at this time.
0 commit comments