// @ts-nocheck import { expect } from 'chai'; import * as errors from '../../src/errors'; describe('Errors', () => { const errorClassNames = [ 'BadRequestError', 'UnauthorizedError', 'ForbiddenError', 'NotFoundError', 'ServerError', 'InvalidResponseError', 'EmptyResultError', 'ValidationError' ]; errorClassNames.forEach(className => { describe(className, testClass(className)); }); function testClass(className) { return () => { const message = 'some kind of server error!'; const mockDataValue = 'some kind of information on the error'; it('should be constructable', () => { const error = new errors[className](message, {}); expect(error).to.be.instanceof(errors[className]); }); it('should expose a message property', () => { const error = new errors[className](message, {}); expect(error.message).to.equal(message); }); it('should expose a stack property', () => { const error = new errors[className](message, {}); expect(error.stack).to.exist; }); it('should expose the data attribute', () => { const error = new errors[className](message, mockDataValue); expect(error.data).to.equal(mockDataValue); }); it('should format nicely when passed into a string', () => { const error = new errors[className](message, {}); expect(`${ error }`).to.contain(`${ className }: ${ message }`); }); }; } });