From 6e02dbb384e62eaebb596682363ca6f28d85fcd8 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 25 Jul 2017 10:16:06 -0700 Subject: [PATCH] test(document): repro #5473 --- test/document.test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/document.test.js b/test/document.test.js index 860593c8c9d..9438861cd23 100644 --- a/test/document.test.js +++ b/test/document.test.js @@ -4328,6 +4328,33 @@ describe('document', function() { }); }); + it('dotted virtuals in toObject (gh-5473)', function(done) { + var schema = new mongoose.Schema({}, { + toObject: { virtuals: true }, + toJSON: { virtuals: true } + }); + schema.virtual('test.a').get(function() { + return 1; + }); + schema.virtual('test.b').get(function() { + return 2; + }); + + var Model = mongoose.model('gh5473', schema); + + var m = new Model({}); + assert.deepEqual(m.toJSON().test, { + a: 1, + b: 2 + }); + assert.deepEqual(m.toObject().test, { + a: 1, + b: 2 + }); + assert.equal(m.toObject({ virtuals: false }).test, void 0); + done(); + }); + it('consistent setter context for single nested (gh-5363)', function(done) { var contentSchema = new Schema({ blocks: [{ type: String }],