From 03f7e5d5bae2a610e5fa9350626c6022092c0ac9 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 12 Feb 2021 13:22:22 -0500 Subject: [PATCH] test(document): repro #9889 --- test/document.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/document.test.js b/test/document.test.js index 104f50220a..4bc194033e 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -5873,6 +5873,30 @@ describe('document', function() { assert.equal(called, 1); }); + it('doesnt call setters when init-ing an array (gh-9889)', function() { + let called = 0; + const testSchema = new mongoose.Schema({ + arr: [{ + type: 'ObjectId', + set: v => { + ++called; + return v; + } + }] + }); + + const Test = db.model('Test', testSchema); + + return co(function*() { + let doc = yield Test.create({ arr: [new mongoose.Types.ObjectId()] }); + assert.equal(called, 1); + + called = 0; + doc = yield Test.findById(doc); + assert.equal(called, 0); + }); + }); + it('nested virtuals + nested toJSON (gh-6294)', function() { const schema = mongoose.Schema({ nested: {