From 4364c7264b4eb0e00d043695b98a83361f47139b Mon Sep 17 00:00:00 2001 From: vector Date: Fri, 8 Dec 2023 02:09:08 +0800 Subject: [PATCH 1/3] test: add unit test for assert for increase coverage to 100% --- packages/utils/src/assert.spec.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/assert.spec.ts b/packages/utils/src/assert.spec.ts index 669405a597..2631596b42 100644 --- a/packages/utils/src/assert.spec.ts +++ b/packages/utils/src/assert.spec.ts @@ -1,6 +1,17 @@ -import { assertDefined, assertDefinedAndNotNull } from "./assert"; +import { assert, assertDefined, assertDefinedAndNotNull } from "./assert"; describe("assert", () => { + + describe("assert", () => { + it('assert should not throw an error when condition is truthy', () => { + expect(() => assert(true)).not.toThrow(); + }); + + it('assert should throw an error with default message when condition is falsy', () => { + expect(() => assert(false)).toThrowError("condition is not truthy"); + }); + }); + describe("assertDefined", () => { it("passes for simple values", () => { { From 441a25ed78a5596d9b1dc76861d1d48b433bba0e Mon Sep 17 00:00:00 2001 From: vector Date: Fri, 8 Dec 2023 02:09:45 +0800 Subject: [PATCH 2/3] test: add custom message test case for assert --- packages/utils/src/assert.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/utils/src/assert.spec.ts b/packages/utils/src/assert.spec.ts index 2631596b42..4defd93660 100644 --- a/packages/utils/src/assert.spec.ts +++ b/packages/utils/src/assert.spec.ts @@ -10,6 +10,11 @@ describe("assert", () => { it('assert should throw an error with default message when condition is falsy', () => { expect(() => assert(false)).toThrowError("condition is not truthy"); }); + + it('assert should throw an error with custom message when condition is falsy', () => { + const errorMessage = "Custom error message"; + expect(() => assert(false, errorMessage)).toThrowError(errorMessage); + }); }); describe("assertDefined", () => { From 9c49f68f97e562c3a76908bf1d4e3697d22d1952 Mon Sep 17 00:00:00 2001 From: vector Date: Fri, 8 Dec 2023 10:20:42 +0800 Subject: [PATCH 3/3] fix: fix lint issue --- packages/utils/src/assert.spec.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/utils/src/assert.spec.ts b/packages/utils/src/assert.spec.ts index 4defd93660..3e98245247 100644 --- a/packages/utils/src/assert.spec.ts +++ b/packages/utils/src/assert.spec.ts @@ -1,17 +1,16 @@ import { assert, assertDefined, assertDefinedAndNotNull } from "./assert"; describe("assert", () => { - describe("assert", () => { - it('assert should not throw an error when condition is truthy', () => { + it("assert should not throw an error when condition is truthy", () => { expect(() => assert(true)).not.toThrow(); }); - it('assert should throw an error with default message when condition is falsy', () => { + it("assert should throw an error with default message when condition is falsy", () => { expect(() => assert(false)).toThrowError("condition is not truthy"); }); - it('assert should throw an error with custom message when condition is falsy', () => { + it("assert should throw an error with custom message when condition is falsy", () => { const errorMessage = "Custom error message"; expect(() => assert(false, errorMessage)).toThrowError(errorMessage); });