Skip to content

Commit

Permalink
update expected error test to be a catch
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Oct 17, 2024
1 parent 8d45c13 commit 3f6c223
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/shell-api/src/collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,26 +1165,29 @@ describe('Collection', function () {
context(
'when serviceProvider.dropIndexes rejects IndexNotFound',
function () {
let expectedError: Error;
beforeEach(function () {
const error = new Error('index not found with name [index_1]');
Object.assign(error, {
expectedError = new Error('index not found with name [index_1]');
Object.assign(expectedError, {
ok: 0,
errmsg: 'index not found with name [index_1]',
code: 27,
codeName: 'IndexNotFound',
name: 'MongoError',
name: 'MongoServerError',
});

serviceProvider.runCommandWithCheck.rejects(error);
serviceProvider.runCommandWithCheck.rejects(expectedError);
});

it('returns the error as object', async function () {
expect(await collection.dropIndexes('index_1')).to.deep.equal({
ok: 0,
errmsg: 'index not found with name [index_1]',
code: 27,
codeName: 'IndexNotFound',
});
let caughtError: Error | undefined;
expect(
await collection
.dropIndexes('index_1')
.catch((err) => (caughtError = err))
);

expect(caughtError).to.deep.equal(expectedError);
});
}
);
Expand Down

0 comments on commit 3f6c223

Please sign in to comment.