diff options
author | Linus Groh <mail@linusgroh.de> | 2021-06-11 20:40:08 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-11 21:34:05 +0100 |
commit | 862ba6403738224ce683397d496ac43dcb806e1c (patch) | |
tree | 2adb774b7ad77455113279c280dc59e01d52c33f /Userland/Libraries/LibJS/Tests/builtins | |
parent | 8d77a3297a0722e6f6dcb0ffb564ed016c0cfc20 (diff) | |
download | serenity-862ba6403738224ce683397d496ac43dcb806e1c.zip |
LibJS: Implement the Error Cause proposal
Currently stage 3. https://github.com/tc39/proposal-error-cause
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/builtins')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/AggregateError/AggregateError.js | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Error/Error.js | 27 |
2 files changed, 34 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/AggregateError/AggregateError.js b/Userland/Libraries/LibJS/Tests/builtins/AggregateError/AggregateError.js index de73e18e3a..1578d823ad 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/AggregateError/AggregateError.js +++ b/Userland/Libraries/LibJS/Tests/builtins/AggregateError/AggregateError.js @@ -56,4 +56,11 @@ describe("normal behavior", () => { }).errors ).toEqual(errors); }); + + test("supports options object with cause", () => { + const cause = new Error(); + const error = new AggregateError([], "test", { cause }); + expect(error.hasOwnProperty("cause")).toBeTrue(); + expect(error.cause).toBe(cause); + }); }); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Error/Error.js b/Userland/Libraries/LibJS/Tests/builtins/Error/Error.js index 2926e0741c..82e61674db 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Error/Error.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Error/Error.js @@ -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); + }); }); |