Skip to content

Commit d682c52

Browse files
committed
Add tests for fullMessageWithStack
1 parent b33b5bb commit d682c52

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

extensions/ql-vscode/test/unit-tests/common/errors.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,40 @@ describe("errorMessage", () => {
1919
).toEqual("Failed to create database foo");
2020
});
2121

22+
it("fullMessageWithStack includes the stack", () => {
23+
expect(
24+
redactableError`Failed to create database ${"foo"}`.fullMessageWithStack,
25+
).toMatch(
26+
/^Failed to create database foo\nError: Failed to create database foo\n +at redactableError \(/,
27+
);
28+
});
29+
30+
it("fullMessageWithStack includes the cause stack for given error", () => {
31+
function myRealFunction() {
32+
throw new Error("Internal error");
33+
}
34+
35+
let error: Error;
36+
try {
37+
myRealFunction();
38+
39+
fail("Expected an error to be thrown");
40+
} catch (e: unknown) {
41+
if (!(e instanceof Error)) {
42+
throw new Error("Expected an Error to be thrown");
43+
}
44+
45+
error = e;
46+
}
47+
48+
expect(
49+
redactableError(error)`Failed to create database ${"foo"}`
50+
.fullMessageWithStack,
51+
).toMatch(
52+
/^Failed to create database foo\nError: Internal error\n +at myRealFunction \(/,
53+
);
54+
});
55+
2256
it("redactedMessage redacts the given message", () => {
2357
expect(
2458
redactableError`Failed to create database ${"foo"}`.redactedMessage,

0 commit comments

Comments
 (0)