From 249db10d42cba7ff1152fb731341baf4a87596ad Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Tue, 19 Mar 2024 15:22:19 +0100 Subject: [PATCH] test: `error.ts` --- test/unit/error.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/unit/error.test.ts diff --git a/test/unit/error.test.ts b/test/unit/error.test.ts new file mode 100644 index 0000000..5e8d39e --- /dev/null +++ b/test/unit/error.test.ts @@ -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]` + ); + }); +});