Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Adding more tests for createError
Browse files Browse the repository at this point in the history
  • Loading branch information
RC-Lee committed Feb 17, 2022
1 parent 4b4fd22 commit c831d2e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,12 +893,37 @@ describe('hash', () => {
describe('Create Error tests for Satellite', () => {
test('should be an instance of type Error', () => {
expect(createError(404, 'testing') instanceof Error).toBe(true);

const testError = createError(404, 'Test for Errors');
const nestedError = createError(testError);
expect(nestedError instanceof Error).toBe(true);
});

test("should have it's value, and message accessible through it's members", () => {
const testError = createError(404, 'Satellite Test for Errors');
expect(testError.status).toBe(404);
expect(testError.message).toBe('Satellite Test for Errors');

const nestedError = createError(testError);
expect(nestedError.status).toBe(404);
expect(nestedError.message).toBe('Satellite Test for Errors');
});

test('should fail when creating Error from ElasticSearch error object', async () => {
// { errors } is imported from ElasticSearch
const elasticError = new errors.ResponseError({
body: { error: 'testingElasticError' },
statusCode: 404,
});

try {
createError(503, elasticError);
} catch (err) {
expect(err instanceof TypeError).toBe(true);
expect(err.message).toBe(
'Cannot set property statusCode of [object Object] which has only a getter'
);
}
});
});

Expand Down

0 comments on commit c831d2e

Please sign in to comment.