summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/builtins/Reflect/Reflect.preventExtensions.js
blob: 6b0bfdc1bcb97b7ccada86eb63a25b401ec1269b (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
describe("errors", () => {
    test("target must be an object", () => {
        [null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
            expect(() => {
                Reflect.preventExtensions(value);
            }).toThrowWithMessage(
                TypeError,
                "First argument of Reflect.preventExtensions() must be an object"
            );
        });
    });
});

describe("normal behavior", () => {
    test("length is 1", () => {
        expect(Reflect.preventExtensions).toHaveLength(1);
    });

    test("properties cannot be added", () => {
        var o = {};
        o.foo = "foo";
        expect(Reflect.preventExtensions(o)).toBeTrue();
        o.bar = "bar";
        expect(o.foo).toBe("foo");
        expect(o.bar).toBeUndefined();
    });

    test("modifying existing properties", () => {
        const o = {};
        o.foo = "foo";
        expect(Reflect.preventExtensions(o)).toBeTrue();
        o.foo = "bar";
        expect(o.foo).toBe("bar");
    });

    test("deleting existing properties", () => {
        const o = { foo: "bar" };
        Reflect.preventExtensions(o);
        delete o.foo;
        expect(o).not.toHaveProperty("foo");
    });
});