Skip to content

Commit 51a590f

Browse files
committed
test: add test case re: #13145, #13903
1 parent 11ae61f commit 51a590f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/document.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12493,6 +12493,29 @@ describe('document', function() {
1249312493
assert.strictEqual(parent.get('child.concreteProp'), 123);
1249412494
assert.strictEqual(parent.toObject().child.concreteProp, 123);
1249512495
});
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+
});
1249612519
});
1249712520

1249812521
describe('Check if instance function that is supplied in schema option is availabe', function() {

0 commit comments

Comments
 (0)