From a0ee7b94c2a899736c9ad9604c81966a72dff65b Mon Sep 17 00:00:00 2001 From: Bauke Date: Tue, 27 Dec 2022 21:03:27 +0100 Subject: [PATCH] Add a false assertion. --- source/test.ts | 10 ++++++++++ tests/assertions.ts | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/source/test.ts b/source/test.ts index 70eebdc..f21b0f1 100644 --- a/source/test.ts +++ b/source/test.ts @@ -28,6 +28,16 @@ export class TestContext { ); } + /** Assert that the value is false. */ + false(actual: boolean, title?: string): void { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare + if (actual === false) { + return; + } + + throw new AssertionError("Failed false assertion", actual, false, title); + } + /** Assert that the value is true. */ true(actual: boolean, title?: string): void { // eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare diff --git a/tests/assertions.ts b/tests/assertions.ts index b3558aa..cc96b0d 100644 --- a/tests/assertions.ts +++ b/tests/assertions.ts @@ -7,6 +7,11 @@ await setup("Assertions", async (group) => { test.equals("A string!", "A string!", "string"); }); + group.test("false", async (test) => { + test.false(1 < 0, "logic"); + test.false(new Date() instanceof String, "instanceof"); + }); + group.test("true", async (test) => { test.true(1 > 0, "logic"); test.true(new Date() instanceof Date, "instanceof");