Skip to content

Commit

Permalink
test(query): add test case for #13165
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 21, 2023
1 parent 4339105 commit 18b03a0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2385,15 +2385,13 @@ describe('Query', function() {
});

it('findOne()', async function() {
let threw = false;
try {
await Model.findOne({ name: 'na' }).orFail(() => new Error('Oops!'));
assert.ok(false);
} catch (error) {
assert.ok(error);
assert.equal(error.message, 'Oops!');
threw = true;
}
assert.ok(threw);

// Shouldn't throw
const res = await Model.findOne({ name: 'Test' }).orFail(new Error('Oops'));
Expand Down Expand Up @@ -2554,6 +2552,16 @@ describe('Query', function() {
assert.ok(err.message.indexOf('"Test"') !== -1, err.message);
assert.deepEqual(err.filter, { name: 'na' });
});

it('does not fire on CastError (gh-13165)', async function() {
try {
await Model.findOne({ _id: 'bad' }).orFail();
assert.ok(false);
} catch (error) {
assert.ok(error);
assert.equal(error.name, 'CastError');
}
});
});

describe('getPopulatedPaths', function() {
Expand Down

0 comments on commit 18b03a0

Please sign in to comment.