mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:17:45 +00:00
LibJS: Implement AggregateError
This commit is contained in:
parent
2f03eb8628
commit
cbd7437d40
13 changed files with 301 additions and 15 deletions
|
@ -0,0 +1,59 @@
|
|||
describe("errors", () => {
|
||||
test("first argument must be coercible to object", () => {
|
||||
expect(() => {
|
||||
new AggregateError();
|
||||
}).toThrowWithMessage(TypeError, "ToObject on null or undefined");
|
||||
});
|
||||
|
||||
test("@@iterator throws", () => {
|
||||
expect(() => {
|
||||
new AggregateError({
|
||||
[Symbol.iterator]() {
|
||||
throw Error("oops!");
|
||||
},
|
||||
});
|
||||
}).toThrowWithMessage(Error, "oops!");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("length is 2", () => {
|
||||
expect(AggregateError).toHaveLength(2);
|
||||
});
|
||||
|
||||
test("name is AggregateError", () => {
|
||||
expect(AggregateError.name).toBe("AggregateError");
|
||||
});
|
||||
|
||||
test("Prototype of the AggregateError constructor is the Error constructor", () => {
|
||||
expect(Object.getPrototypeOf(AggregateError)).toBe(Error);
|
||||
});
|
||||
|
||||
test("Prototype of AggregateError.prototype is Error.prototype", () => {
|
||||
expect(Object.getPrototypeOf(AggregateError.prototype)).toBe(Error.prototype);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
expect(AggregateError([])).toBeInstanceOf(AggregateError);
|
||||
expect(new AggregateError([])).toBeInstanceOf(AggregateError);
|
||||
expect(new AggregateError([]).toString()).toBe("AggregateError");
|
||||
expect(new AggregateError([], "Foo").toString()).toBe("AggregateError: Foo");
|
||||
expect(new AggregateError([]).hasOwnProperty("errors")).toBeTrue();
|
||||
const errors = [1, 2, 3];
|
||||
expect(new AggregateError(errors).errors).toEqual(errors);
|
||||
expect(new AggregateError(errors).errors).not.toBe(errors);
|
||||
expect(
|
||||
new AggregateError({
|
||||
[Symbol.iterator]: (i = 0) => ({
|
||||
next() {
|
||||
if (i < 3) {
|
||||
i++;
|
||||
return { value: i };
|
||||
}
|
||||
return { value: null, done: true };
|
||||
},
|
||||
}),
|
||||
}).errors
|
||||
).toEqual(errors);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue