mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
LibJS: Implement the Error Cause proposal
Currently stage 3. https://github.com/tc39/proposal-error-cause
This commit is contained in:
parent
8d77a3297a
commit
862ba64037
11 changed files with 130 additions and 42 deletions
|
@ -31,4 +31,31 @@ describe("normal behavior", () => {
|
|||
expect(TypeError()).toBeInstanceOf(TypeError);
|
||||
expect(new TypeError()).toBeInstanceOf(TypeError);
|
||||
});
|
||||
|
||||
test("supports options object with cause", () => {
|
||||
const errors = [Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError];
|
||||
const cause = new Error();
|
||||
errors.forEach(T => {
|
||||
const error = new T("test", { cause });
|
||||
expect(error.hasOwnProperty("cause")).toBeTrue();
|
||||
expect(error.cause).toBe(cause);
|
||||
});
|
||||
});
|
||||
|
||||
test("supports options object with cause (chained)", () => {
|
||||
let error;
|
||||
try {
|
||||
try {
|
||||
throw new Error("foo");
|
||||
} catch (e) {
|
||||
throw new Error("bar", { cause: e });
|
||||
}
|
||||
} catch (e) {
|
||||
error = new Error("baz", { cause: e });
|
||||
}
|
||||
expect(error.message).toBe("baz");
|
||||
expect(error.cause.message).toBe("bar");
|
||||
expect(error.cause.cause.message).toBe("foo");
|
||||
expect(error.cause.cause.cause).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue