Skip to content

Commit

Permalink
test(document): repro #9889
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Feb 12, 2021
1 parent 7b9ccb0 commit 03f7e5d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 03f7e5d

Please sign in to comment.