Files
outline/shared/utils/error.test.ts
Tom Moor 66eee9007f chore: Upgrade to Typescript 6 (#12737)
* chore: Upgrade TypeScript to 6.0
2026-06-18 17:34:05 -04:00

37 lines
1.1 KiB
TypeScript

import { toError, errToString } from "./error";
describe("toError", () => {
it("returns the same Error instance when given an Error", () => {
const error = new Error("boom");
expect(toError(error)).toBe(error);
});
it("preserves Error subclasses", () => {
const error = new TypeError("nope");
expect(toError(error)).toBe(error);
});
it("wraps a string in an Error", () => {
expect(toError("boom")).toBeInstanceOf(Error);
expect(toError("boom").message).toBe("boom");
});
it("wraps non-string values using their string representation", () => {
expect(toError(42).message).toBe("42");
expect(toError(null).message).toBe("null");
expect(toError(undefined).message).toBe("undefined");
});
});
describe("errToString", () => {
it("returns the message of an Error", () => {
expect(errToString(new Error("boom"))).toBe("boom");
});
it("returns the string representation of a non-Error", () => {
expect(errToString("boom")).toBe("boom");
expect(errToString(42)).toBe("42");
expect(errToString(undefined)).toBe("undefined");
});
});