-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassert.test.ts
65 lines (59 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.
import { assert } from "./assert.ts";
import { assertEquals } from "./deps_test.ts";
import { isHttpError } from "./http_errors.ts";
import { Status } from "./status.ts";
Deno.test({
name: "assert - does not throw when condition is true",
fn() {
assert(true);
},
});
Deno.test({
name: "assert - throws bad request error",
fn() {
try {
assert(false);
} catch (error) {
if (!isHttpError(error)) {
throw new Error("expected error to be an HttpError");
}
assertEquals(error.status, 400);
assertEquals(error.message, "Assertion failed.");
assertEquals(error.expose, true);
}
},
});
Deno.test({
name: "assert - message is customizable",
fn() {
try {
assert(false, "This is a custom message.");
} catch (error) {
assertEquals(error.message, "This is a custom message.");
}
},
});
Deno.test({
name: "assert - status is customizable",
fn() {
try {
assert(false, "This is a custom message.", Status.NotFound);
} catch (error) {
assertEquals(error.status, 404);
assertEquals(error.expose, true);
}
},
});
Deno.test({
name: "assert - options are passed through",
fn() {
try {
assert(false, "This is a custom message.", Status.NotFound, {
expose: false,
});
} catch (error) {
assertEquals(error.expose, false);
}
},
});