Skip to content

Commit

Permalink
test: error.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Mar 20, 2024
1 parent 21ad284 commit 249db10
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/unit/error.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, expect, test } from 'vitest';

import { FreezerError, raise } from '../../src/error';

describe('Test FreezerError class', () => {
test('without error code', () => {
const error = new FreezerError('Some error');

expect(error).toBeInstanceOf(Error);
expect(error).toBeInstanceOf(FreezerError);

expect(error.message).toMatchInlineSnapshot(`"Some error"`);
expect(error.code).toBeUndefined();
});

test('with error code', () => {
const error = new FreezerError('Some error', 42);

expect(error).toBeInstanceOf(Error);
expect(error).toBeInstanceOf(FreezerError);

expect(error.message).toMatchInlineSnapshot(`"Some error"`);
expect(error.code).toMatchInlineSnapshot(`42`);
});

test('raise error', () => {
expect(() => raise('Some error')).toThrowErrorMatchingInlineSnapshot(
`[Error: Some error]`
);
});
});

0 comments on commit 249db10

Please sign in to comment.