Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions core/util/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ContinueError, ContinueErrorReason, getRootCause } from "./errors";

describe("getRootCause", () => {
test("should return the error itself when it has no cause", () => {
const err = new Error("This is an error");
expect(getRootCause(err)).toBe(err);
});

test("should return the root cause of a nested error", () => {
const rootCause = new Error("This is the root cause");
const err = new Error("This is an error", { cause: rootCause });
expect(getRootCause(err)).toBe(rootCause);
});

test("should return the root cause of a deeply nested error", () => {
const rootCause = new Error("This is the root cause");
const err1 = new Error("This is the first error", { cause: rootCause });
const err2 = new Error("This is the second error", { cause: err1 });
expect(getRootCause(err2)).toBe(rootCause);
});
});

describe("ContinueError", () => {
test("should correctly set the reason and message", () => {
const reason = ContinueErrorReason.Unspecified;
const message = "This is a test error";
const err = new ContinueError(reason, message);
expect(err.reason).toBe(reason);
expect(err.message).toBe(message);
expect(err.name).toBe("ContinueError");
});

test("should have an empty message if none is provided", () => {
const reason = ContinueErrorReason.Unspecified;
const err = new ContinueError(reason);
expect(err.reason).toBe(reason);
expect(err.message).toBe("");
});
});
Loading