Skip to content

Commit

Permalink
test(update): repro #7187
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 11, 2019
1 parent b9c1012 commit 98b3b09
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3549,6 +3549,24 @@ describe('Query', function() {
assert.equal(doc.password, 'encryptedpassword');
});
});

it('pre("validate") errors (gh-7187)', function() {
const addressSchema = Schema({ countryId: String });
addressSchema.pre('validate', { query: true }, function() {
throw new Error('Oops!');
});
const contactSchema = Schema({ addresses: [addressSchema] });
const Contact = db.model('gh7187', contactSchema);

const update = { addresses: [{ countryId: 'foo' }] };
return Contact.updateOne({}, update, { runValidators: true }).then(
() => assert.ok(false),
err => {
assert.ok(err.errors['addresses.0']);
assert.equal(err.errors['addresses.0'].message, 'Oops!');
}
);
});
});

it('query with top-level _bsontype (gh-8222)', function() {
Expand Down

0 comments on commit 98b3b09

Please sign in to comment.