From 1bc047396e9dcd8a591e87c28c953d57a722c0bc Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Thu, 8 Aug 2024 17:21:32 -0500 Subject: [PATCH] Tests (#79-2) --- src/util/assertUtil.spec.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/util/assertUtil.spec.ts diff --git a/src/util/assertUtil.spec.ts b/src/util/assertUtil.spec.ts new file mode 100644 index 00000000..6e0b3c91 --- /dev/null +++ b/src/util/assertUtil.spec.ts @@ -0,0 +1,22 @@ +import { describe, it, expect } from 'vitest'; +import { assertDefined } from './assertUtil'; + +// Example function tests +describe('assertDefined', () => { + it.each([{}, 'test', 999, true, false, new Date()])( + 'should not throw if value is defined: %s', + value => { + assertDefined(value, 'value'); + expect(true).toBe(true); + } + ); + + it.each([null, undefined])( + 'should throw an error for null or undefined values: %s', + value => { + expect(() => assertDefined(value, 'value')).toThrow( + `'value' is required` + ); + } + ); +});