-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy patherrors.test.ts
More file actions
75 lines (63 loc) · 2.25 KB
/
errors.test.ts
File metadata and controls
75 lines (63 loc) · 2.25 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
import { redactableError, RedactableError } from "../../../src/common/errors";
describe("errorMessage", () => {
it("creates a RedactableError", () => {
expect(redactableError`Failed to create database ${"foo"}`).toBeInstanceOf(
RedactableError,
);
});
it("toString() matches the given message", () => {
expect(
redactableError`Failed to create database ${"foo"}`.toString(),
).toEqual("Failed to create database foo");
});
it("fullMessage matches the given message", () => {
expect(
redactableError`Failed to create database ${"foo"}`.fullMessage,
).toEqual("Failed to create database foo");
});
it("fullMessageWithStack includes the stack", () => {
expect(
redactableError`Failed to create database ${"foo"}`.fullMessageWithStack,
).toMatch(
/^Failed to create database foo\nError: Failed to create database foo\n +at redactableError \(/,
);
});
it("fullMessageWithStack includes the cause stack for given error", () => {
function myRealFunction() {
throw new Error("Internal error");
}
let error: Error;
try {
myRealFunction();
fail("Expected an error to be thrown");
} catch (e) {
if (!(e instanceof Error)) {
throw new Error("Expected an Error to be thrown");
}
error = e;
}
expect(
redactableError(error)`Failed to create database ${"foo"}`
.fullMessageWithStack,
).toMatch(
/^Failed to create database foo\nError: Internal error\n +at myRealFunction \(/,
);
});
it("redactedMessage redacts the given message", () => {
expect(
redactableError`Failed to create database ${"foo"}`.redactedMessage,
).toEqual("Failed to create database [REDACTED]");
});
it("fullMessage returns the correct message for nested redactableError", () => {
expect(
redactableError`Failed to create database ${redactableError`foo ${"bar"}`}`
.fullMessage,
).toEqual("Failed to create database foo bar");
});
it("redactedMessage returns the correct message for nested redactableError", () => {
expect(
redactableError`Failed to create database ${redactableError`foo ${"bar"}`}`
.redactedMessage,
).toEqual("Failed to create database foo [REDACTED]");
});
});