summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/builtins
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/builtins')
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/AggregateError/AggregateError.js7
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Error/Error.js27
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);
+ });
});