Compare commits

...

2 Commits

Author SHA1 Message Date
Bauke a0ee7b94c2
Add a false assertion. 2022-12-27 21:03:27 +01:00
Bauke 85b835eba1
Add a true assertion and assertion test file. 2022-12-27 20:16:54 +01:00
3 changed files with 41 additions and 0 deletions

View File

@ -27,6 +27,26 @@ export class TestContext {
title,
);
}
/** 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
if (actual === true) {
return;
}
throw new AssertionError("Failed true assertion", actual, true, title);
}
}
/** Special options for test cases. */

19
tests/assertions.ts Normal file
View File

@ -0,0 +1,19 @@
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("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");
});
});

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(() => {