Add tests for fullMessageWithStack

This commit is contained in:
Koen Vlaswinkel 2023-10-23 10:44:25 +02:00
Родитель b33b5bb7c4
Коммит d682c520d5
1 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@ -19,6 +19,40 @@ describe("errorMessage", () => {
).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: unknown) {
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,