Add a true assertion and assertion test file.

This commit is contained in:
Bauke 2022-12-27 20:16:54 +01:00
parent a0d46f7018
commit 85b835eba1
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 26 additions and 0 deletions

View File

@ -27,6 +27,16 @@ export class TestContext {
title,
);
}
/** Assert that the value is true. */
true(actual: boolean, title?: string): void {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
if (actual === true) {
return;
}
throw new AssertionError("Failed true assertion", actual, true, title);
}
}
/** Special options for test cases. */

14
tests/assertions.ts Normal file
View File

@ -0,0 +1,14 @@
import {setup} from "../source/index.js";
await setup("Assertions", async (group) => {
group.test("equals", async (test) => {
test.equals(true, true, "boolean");
test.equals(Math.PI, Math.PI, "number");
test.equals("A string!", "A string!", "string");
});
group.test("true", async (test) => {
test.true(1 > 0, "logic");
test.true(new Date() instanceof Date, "instanceof");
});
});

View File

@ -1,5 +1,7 @@
import {setup} from "../source/index.js";
await import("./assertions.js");
async function add(a: number, b: number): Promise<number> {
await new Promise<void>((resolve) => {
setTimeout(() => {