From 6ea62ddd37eb981a83cda77399af11c4d3663077 Mon Sep 17 00:00:00 2001 From: Hafez Date: Sun, 17 Nov 2019 22:25:47 +0200 Subject: [PATCH] Reproduce #8317 --- test/types.documentarray.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/types.documentarray.test.js b/test/types.documentarray.test.js index 1a148714750..4b31ee82cce 100644 --- a/test/types.documentarray.test.js +++ b/test/types.documentarray.test.js @@ -575,6 +575,20 @@ describe('types.documentarray', function() { assert.equal(arr.length, 1); assert.equal(doc.docs.length, 2); }); + + it('map() copies parent and path ()', function() { + const personSchema = new Schema({ friends: [{ name: { type: String } }]}); + const Person = mongoose.model('Person', personSchema); + + const person = new Person({ friends: [{ name: 'Hafez' }] }); + + const friendsNames = person.friends.map(friend => friend.name); + + friendsNames.push('Sam'); + + assert.equal(friendsNames.length, 2); + assert.equal(friendsNames[1], 'Sam'); + }); }); it('cleans modified subpaths on splice() (gh-7249)', function() {