Skip to content

Commit 98b3b09

Browse files
committed
test(update): repro #7187
1 parent b9c1012 commit 98b3b09

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/query.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -3549,6 +3549,24 @@ describe('Query', function() {
35493549
assert.equal(doc.password, 'encryptedpassword');
35503550
});
35513551
});
3552+
3553+
it('pre("validate") errors (gh-7187)', function() {
3554+
const addressSchema = Schema({ countryId: String });
3555+
addressSchema.pre('validate', { query: true }, function() {
3556+
throw new Error('Oops!');
3557+
});
3558+
const contactSchema = Schema({ addresses: [addressSchema] });
3559+
const Contact = db.model('gh7187', contactSchema);
3560+
3561+
const update = { addresses: [{ countryId: 'foo' }] };
3562+
return Contact.updateOne({}, update, { runValidators: true }).then(
3563+
() => assert.ok(false),
3564+
err => {
3565+
assert.ok(err.errors['addresses.0']);
3566+
assert.equal(err.errors['addresses.0'].message, 'Oops!');
3567+
}
3568+
);
3569+
});
35523570
});
35533571

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

0 commit comments

Comments
 (0)