diff --git a/test/model.hydrate.test.js b/test/model.hydrate.test.js index 6cdc333ce8d..cabdf7d225f 100644 --- a/test/model.hydrate.test.js +++ b/test/model.hydrate.test.js @@ -99,5 +99,23 @@ describe('model', function() { assert.equal(hydrated.test, 'test'); assert.deepEqual(hydrated.schema.tree, C.schema.tree); }); + it('should deeply hydrate the document with the `hydratedPopulatedDocs` option (gh-4727)', async function() { + const userSchema = new Schema({ + name: String + }); + const companySchema = new Schema({ + name: String, + users: [{ ref: 'User', type: Schema.Types.ObjectId }] + }); + + const User = db.model('UserTestHydrate', userSchema); + const Company = db.model('CompanyTestHyrdrate', companySchema); + + const users = [{ _id: new Schema.ObjectId(), name: 'Val'}]; + const company = { _id: new Schema.ObjectId(), name: 'Booster', users: [users[0]] }; + + const C = Company.hydrate(company, null, { hydratedPopulatedDocs: true }); + assert.equal(C.users[0].name, 'Val'); + }); }); });