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 7c41ddc commit 1e9eda3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5853,6 +5853,26 @@ describe('document', function() {
assert.equal(doc.totalValue, 5);
});

it('calls array getters (gh-9889)', function() {
let called = 0;
const testSchema = new mongoose.Schema({
arr: [{
type: 'ObjectId',
ref: 'Doesnt Matter',
get: () => {
++called;
return 42;
}
}]
});

const Test = db.model('Test', testSchema);

const doc = new Test({ arr: [new mongoose.Types.ObjectId()] });
assert.deepEqual(doc.toObject({ getters: true }).arr, [42]);
assert.equal(called, 1);
});

it('nested virtuals + nested toJSON (gh-6294)', function() {
const schema = mongoose.Schema({
nested: {
Expand Down

0 comments on commit 1e9eda3

Please sign in to comment.