summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js
blob: ec12161d3319983cb69f594075f1c57f4555a7c3 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
test("plain property", () => {
    let o = { foo: "bar" };

    expect(o).toHaveConfigurableProperty("foo");
    expect(o).toHaveEnumerableProperty("foo");
    expect(o).toHaveWritableProperty("foo");
    expect(o).toHaveValueProperty("foo", "bar");
    expect(o).not.toHaveGetterProperty("foo");
    expect(o).not.toHaveSetterProperty("foo");
});

test("symbol property", () => {
    let s = Symbol("foo");
    let o = { [s]: "bar" };

    expect(o).toHaveConfigurableProperty(s);
    expect(o).toHaveEnumerableProperty(s);
    expect(o).toHaveWritableProperty(s);
    expect(o).toHaveValueProperty(s, "bar");
    expect(o).not.toHaveGetterProperty(s);
    expect(o).not.toHaveSetterProperty(s);
});

test("getter property", () => {
    let o = { get foo() {} };

    expect(o).toHaveConfigurableProperty("foo");
    expect(o).toHaveEnumerableProperty("foo");
    expect(o).not.toHaveWritableProperty("foo");
    expect(o).not.toHaveValueProperty("foo");
    expect(o).toHaveGetterProperty("foo");
    expect(o).not.toHaveSetterProperty("foo");
});

test("setter property", () => {
    let o = { set foo(_) {} };

    expect(o).toHaveConfigurableProperty("foo");
    expect(o).toHaveEnumerableProperty("foo");
    expect(o).not.toHaveWritableProperty("foo");
    expect(o).not.toHaveValueProperty("foo");
    expect(o).not.toHaveGetterProperty("foo");
    expect(o).toHaveSetterProperty("foo");
});

test("indexed property", () => {
    let o = { 0: "foo" };

    expect(o).toHaveConfigurableProperty(0);
    expect(o).toHaveEnumerableProperty(0);
    expect(o).toHaveWritableProperty(0);
    expect(o).toHaveValueProperty(0, "foo");
    expect(o).not.toHaveGetterProperty(0);
    expect(o).not.toHaveSetterProperty(0);

    expect(o).toHaveConfigurableProperty("0");
    expect(o).toHaveEnumerableProperty("0");
    expect(o).toHaveWritableProperty("0");
    expect(o).toHaveValueProperty("0", "foo");
    expect(o).not.toHaveGetterProperty("0");
    expect(o).not.toHaveSetterProperty("0");
});

test("defined property", () => {
    let o = {};

    const attributes = {
        enumerable: false,
        writable: true,
        value: 10,
    };
    Object.defineProperty(o, "foo", attributes);
    Object.defineProperty(o, 1, attributes);

    expect(o).not.toHaveConfigurableProperty("foo");
    expect(o).not.toHaveEnumerableProperty("foo");
    expect(o).toHaveWritableProperty("foo");
    expect(o).toHaveValueProperty("foo", 10);
    expect(o).not.toHaveGetterProperty("foo");
    expect(o).not.toHaveSetterProperty("foo");

    expect(o).not.toHaveConfigurableProperty(1);
    expect(o).not.toHaveEnumerableProperty(1);
    expect(o).toHaveWritableProperty(1);
    expect(o).toHaveValueProperty(1, 10);
    expect(o).not.toHaveGetterProperty(1);
    expect(o).not.toHaveSetterProperty(1);
});

test("String object indexed properties", () => {
    expect("foo").toHaveValueProperty(0, "f");
    expect("foo").toHaveEnumerableProperty(0);
    expect("foo").not.toHaveConfigurableProperty(0);
    expect("foo").not.toHaveWritableProperty(0);

    expect("foo").toHaveValueProperty(1, "o");
});