Add tests for fullMessageWithStack
This commit is contained in:
@@ -19,6 +19,40 @@ describe("errorMessage", () => {
|
|||||||
).toEqual("Failed to create database foo");
|
).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", () => {
|
it("redactedMessage redacts the given message", () => {
|
||||||
expect(
|
expect(
|
||||||
redactableError`Failed to create database ${"foo"}`.redactedMessage,
|
redactableError`Failed to create database ${"foo"}`.redactedMessage,
|
||||||
|
|||||||
Reference in New Issue
Block a user