-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.ts
More file actions
84 lines (73 loc) · 2.2 KB
/
test.ts
File metadata and controls
84 lines (73 loc) · 2.2 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { assertEqual, equal } from "https://deno.land/x/testing/mod.ts";
import { t } from "https://raw.githubusercontent.com/zhmushan/deno_test/master/index.ts";
import { AssertionError } from "index.ts";
t("construction", function() {
const err = new AssertionError();
assertEqual(err instanceof Error, true, "instanceof Error");
assertEqual(err instanceof AssertionError, true, "instanceof AssertionError");
assertEqual(
err.name && err.name === "AssertionError",
true,
'name === "AssertionError"'
);
});
t("message", function() {
const err = new AssertionError("Oops."),
empty = new AssertionError();
assertEqual(err.message === "Oops.", true, "w/ err.message");
assertEqual(
empty.message === "Unspecified AssertionError",
true,
"w/o err.message"
);
});
t("stack", function() {
assertEqual(typeof new AssertionError().stack === "string", true);
});
t("custom properties", function() {
const err = new AssertionError("good message", {
name: "ShouldNotExist",
hello: "universe",
message: "bad message",
stack: "custom stack"
});
assertEqual(err.name === "AssertionError", true, "does not overwrite name");
assertEqual(
err.message === "good message",
true,
"does not overwrite message"
);
assertEqual(
err["hello"] && err["hello"] === "universe",
true,
"has custom property"
);
// some browsers don't have stack
if (err.stack) {
assertEqual(
err.stack && err.stack !== "custom stack",
true,
"does not overwrite stack"
);
}
});
t(".toJSON()", function() {
const err = new AssertionError("some message", {
hello: "universe",
goodbye: "known"
});
const json = err.toJSON();
assertEqual(json["name"] === "AssertionError", true, "json has name");
assertEqual(json["message"] === "some message", true, "json has message");
assertEqual(
json["hello"] === "universe" && json["goodbye"] === "known",
true,
"json has custom properties"
);
// some browsers don't have stack
if (err.stack) {
assertEqual("string" === typeof json["stack"], true, "json has stack");
}
const nostack = err.toJSON(false);
assertEqual(!nostack["stack"], true, "no stack on false argument");
});