Skip to content

Commit

Permalink
Add test to fiter
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanHafez committed Nov 18, 2019
1 parent ba2c353 commit ba38d1d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/types.documentarray.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,25 @@ describe('types.documentarray', function() {
assert.equal(friendsNames.length, 2);
assert.equal(friendsNames[1], 'Sam');
});

it('filter() copies parent and path (gh-8317)', function() {
const personSchema = new Schema({ friends: [{ name: { type: String }, age: { type: Number } }] });
const Person = mongoose.model('gh8317-filter', personSchema);

const person = new Person({ friends: [
{ name: 'Hafez', age: 25 },
{ name: 'Sam', age: 27 }
] });

const filteredFriends = person.friends.filter(friend => friend.age > 26);
assert.ok(filteredFriends.isMongooseArray);
assert.equal(filteredFriends.constructor.name, 'CoreDocumentArray');

filteredFriends.push({ name: 'John', age: 30 });

assert.equal(filteredFriends.length, 2);
assert.equal(filteredFriends[1].name, 'John');
});
});

it('cleans modified subpaths on splice() (gh-7249)', function() {
Expand Down

0 comments on commit ba38d1d

Please sign in to comment.