From 087a9827d420ca4add04c6522482894179a45598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gromit=20=28=EC=A0=84=EB=AF=BC=EC=9E=AC=29?= <64779472+ssi02014@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:45:12 +0900 Subject: [PATCH] test(invariant): add invariant test code (#789) --- src/util/invariant.spec.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/util/invariant.spec.ts b/src/util/invariant.spec.ts index 1f9add40..21a6d39a 100644 --- a/src/util/invariant.spec.ts +++ b/src/util/invariant.spec.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, expectTypeOf, it } from 'vitest'; import { invariant } from './invariant'; describe('invariant', () => { @@ -30,4 +30,14 @@ describe('invariant', () => { const number = -1; expect(() => invariant(number > 0, 'Number must be positive')).toThrow('Number must be positive'); }); + + it('should assert non-null value and treat it as string', () => { + const value = 'es-toolkit' as string | null; + + invariant(value !== null, 'Value should not be null'); + + // Narrow the type. + expect(value.length).toBe(10); + expectTypeOf(value).toEqualTypeOf(); + }); });