Skip to content

Commit

Permalink
test(map): repro #9813
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 19, 2021
1 parent 6b65d0d commit bcaad30
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/types.map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,4 +976,29 @@ describe('Map', function() {
assert.ifError(doc.validateSync());
});
});

it('handles map of arrays (gh-9813)', function() {
const BudgetSchema = new mongoose.Schema({
budgeted: {
type: Map,
of: [Number]
}
});

const Budget = db.model('Test', BudgetSchema);

return co(function*() {
const _id = yield Budget.create({
budgeted: new Map([['2020', [100, 200, 300]]])
}).then(doc => doc._id);

const doc = yield Budget.findById(_id);
doc.budgeted.get('2020').set(2, 10);
assert.deepEqual(doc.getChanges(), { $set: { 'budgeted.2020.2': 10 } });
yield doc.save();

const res = yield Budget.findOne();
assert.deepEqual(res.toObject().budgeted.get('2020'), [100, 200, 10]);
});
});
});

0 comments on commit bcaad30

Please sign in to comment.