mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:17:35 +00:00
LibJS: Make Array.prototype.concat generic
This commit is contained in:
parent
2ef9df989f
commit
4152409ac5
2 changed files with 109 additions and 10 deletions
|
@ -203,4 +203,43 @@ describe("ability to work with generic non-array objects", () => {
|
|||
0: "foo",
|
||||
});
|
||||
});
|
||||
|
||||
test("concat", () => {
|
||||
expect(Array.prototype.concat.call(o)).toEqual([o]);
|
||||
expect(Array.prototype.concat.call(o, true)).toEqual([o, true]);
|
||||
expect(Array.prototype.concat.call({}, o)).toEqual([{}, o]);
|
||||
|
||||
const spreadable = {
|
||||
length: 5,
|
||||
0: "foo",
|
||||
1: "bar",
|
||||
3: "baz",
|
||||
[Symbol.isConcatSpreadable]: true,
|
||||
};
|
||||
expect(Array.prototype.concat.call(spreadable)).toEqual([
|
||||
"foo",
|
||||
"bar",
|
||||
undefined,
|
||||
"baz",
|
||||
undefined,
|
||||
]);
|
||||
expect(Array.prototype.concat.call(spreadable, [1, 2])).toEqual([
|
||||
"foo",
|
||||
"bar",
|
||||
undefined,
|
||||
"baz",
|
||||
undefined,
|
||||
1,
|
||||
2,
|
||||
]);
|
||||
expect(Array.prototype.concat.call([1], spreadable, [2])).toEqual([
|
||||
1,
|
||||
"foo",
|
||||
"bar",
|
||||
undefined,
|
||||
"baz",
|
||||
undefined,
|
||||
2,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue