From 203450c25244ef446625d3291982e002a3902e4f Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sun, 17 Nov 2019 09:25:33 -0500 Subject: [PATCH] test(documentarray): repro #8317 --- test/types.documentarray.test.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/types.documentarray.test.js b/test/types.documentarray.test.js index e367250c062..1a148714750 100644 --- a/test/types.documentarray.test.js +++ b/test/types.documentarray.test.js @@ -546,7 +546,7 @@ describe('types.documentarray', function() { }); it('clears listeners on cast error (gh-6723)', function() { - const nested = new Schema({v: {type: Number}}); + const nested = new Schema({ v: Number }); const schema = new Schema({ docs: [nested] }); @@ -559,6 +559,22 @@ describe('types.documentarray', function() { return m.save(); }); + + it('slice() copies parent and path (gh-8317)', function() { + const nested = new Schema({ v: Number }); + const schema = new Schema({ + docs: [nested] + }); + const M = db.model('gh8317', schema); + + const doc = M.hydrate({ docs: [{ v: 1 }, { v: 2 }]}); + let arr = doc.docs; + arr = arr.slice(); + arr.splice(0, 1); + + assert.equal(arr.length, 1); + assert.equal(doc.docs.length, 2); + }); }); it('cleans modified subpaths on splice() (gh-7249)', function() {