summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/string-spread.js
blob: 507bab7710b2577dbd275d0abc13819fd2abe2d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function testArray(arr) {
    return arr.length === 4 && arr[0] === "a" && arr[1] === "b" && arr[2] === "c" && arr[3] === "d";
}

test("spreading string literal", () => {
    expect(["a", ..."bc", "d"]).toEqual(["a", "b", "c", "d"]);
});

test("spreading string variable", () => {
    const s = "bc";
    expect(["a", ...s, "d"]).toEqual(["a", "b", "c", "d"]);
});

test("spreading string in object", () => {
    const obj = { a: "bc" };
    expect(["a", ...obj.a, "d"]).toEqual(["a", "b", "c", "d"]);
});

test("spreading empty string", () => {
    expect([..."", "a", ..."bc", ..."", "d", ...""]).toEqual(["a", "b", "c", "d"]);
});

test("spreading string objects", () => {
    expect([..."", ...[...new String("abc")], "d"]).toEqual(["a", "b", "c", "d"]);
});