Skip to content

Commit

Permalink
test(errors): add error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjozork committed Aug 7, 2022
1 parent d8497df commit 5bb5f91
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { FragmenterError, FragmenterErrorCode } from './errors';

describe('FragmenterError', () => {
describe('isFragmenterError', () => {
it('identifies a FragmenterError', () => {
const error = FragmenterError.create(FragmenterErrorCode.PermissionsError, 'aw hell nah');

expect(FragmenterError.isFragmenterError(error)).toBeTruthy();
});

it('does not identify a not FragmenterError', () => {
const error = new Error('when the amogus imposter is sus');

expect(FragmenterError.isFragmenterError(error)).toBeFalsy();
});
});

describe('parseFromMessage', () => {
it('parses valid FragmenterError', () => {
const msg = 'FragmenterError(PermissionsError): EPERM';

const parsed = FragmenterError.parseFromMessage(msg);

expect(parsed.code).toBe(FragmenterErrorCode.PermissionsError);
expect(parsed.message).toBe('FragmenterError(PermissionsError): EPERM');
});

it('does not parse invalid FragmenterError', () => {
const msg = 'NotAFragmenterError(EPERM)';

expect(() => {
FragmenterError.parseFromMessage(msg);
}).toThrow(expect.objectContaining({ message: 'Could not parse FragmenterError: does not match regex' }));
});
});
});

0 comments on commit 5bb5f91

Please sign in to comment.