Skip to content

Commit

Permalink
test(document): repro #10968
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 19, 2021
1 parent f024075 commit 42ff338
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10744,4 +10744,20 @@ describe('document', function() {
doc.quantity = 26;
await doc.save();
});

it('catches errors in `required` functions (gh-10968)', async function() {
const TestSchema = new Schema({
url: {
type: String,
required: function() {
throw new Error('oops!');
}
}
});
const Test = db.model('Test', TestSchema);

const err = await Test.create({}).then(() => null, err => err);
assert.ok(err);
assert.equal(err.errors['url'].message, 'oops!');
});
});

0 comments on commit 42ff338

Please sign in to comment.