summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/object-method-shorthand.js
blob: 8d8dfd512fc06a200150663ccc145f85227db9b4 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
test("basic method shorthand", () => {
    const o = {
        foo: "bar",
        getFoo() {
            return this.foo;
        },
    };
    expect(o.getFoo()).toBe("bar");
});

test("numeric literal method shorthand", () => {
    const o = {
        foo: "bar",
        12() {
            return this.foo;
        },
    };
    expect(o[12]()).toBe("bar");
});

test("string literal method shorthand", () => {
    const o = {
        foo: "bar",
        "hello friends"() {
            return this.foo;
        },
    };
    expect(o["hello friends"]()).toBe("bar");
});

test("computed property method shorthand", () => {
    const o = {
        foo: "bar",
        [4 + 10]() {
            return this.foo;
        },
    };
    expect(o[14]()).toBe("bar");
});

test("symbol computed property shorthand", () => {
    const s = Symbol("foo");
    const o = {
        foo: "bar",
        [s]() {
            return this.foo;
        },
    };
    expect(o[s]()).toBe("bar");
});