-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert.test.ts
46 lines (42 loc) · 1.43 KB
/
assert.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { assert } from "jsr:@std/assert";
import { assert as myAssert, AssertionFailedError } from "./assert.ts";
import { AbortedTestError } from "./k6-execution-shim.ts";
Deno.test("assert true condition should succeed", () => {
myAssert(true, "true is true");
});
Deno.test("assert default to hard assertions", () => {
try {
myAssert(false, "false is false");
} catch (e) {
// In the Deno runtime, the k6/execution module is not available, so
// the k6-execution-shim module is throwing AbortedTestError instead, whereas
// in the k6 runtime, the esbuild bundle file will ensure k6/execution is used instead.
assert(
e instanceof AbortedTestError,
"assert did not throw AbortedTestError",
);
assert(
e.message === "Test aborted: false is false",
"assert did not throw AbortedTestError with correct message",
);
}
});
Deno.test("assert soft mode", async (t) => {
await t.step("true condition should succeed", () => {
myAssert(true, "true is true", true);
});
await t.step("false condition should throw AssertionFailedError", () => {
try {
myAssert(false, "false is false", true);
} catch (e) {
assert(
e instanceof AssertionFailedError,
"assert did not throw AssertionFailedError",
);
assert(
e.message === "false is false",
"assert did not throw AssertionFailedError with correct message",
);
}
});
});