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
|
test("length is 1", () => {
expect(Object.seal).toHaveLength(1);
});
describe("normal behavior", () => {
test("returns given argument", () => {
const o = {};
expect(Object.seal(42)).toBe(42);
expect(Object.seal("foobar")).toBe("foobar");
expect(Object.seal(o)).toBe(o);
});
test("prevents addition of new properties", () => {
const o = {};
expect(o.foo).toBeUndefined();
Object.seal(o);
o.foo = "bar";
expect(o.foo).toBeUndefined();
});
test("prevents deletion of existing properties", () => {
const o = { foo: "bar" };
expect(o.foo).toBe("bar");
Object.seal(o);
delete o.foo;
expect(o.foo).toBe("bar");
});
test("prevents changing attributes of existing properties", () => {
const o = { foo: "bar" };
Object.seal(o);
// FIXME: These don't change anything and should not throw!
// expect(Object.defineProperty(o, "foo", {})).toBe(o);
// expect(Object.defineProperty(o, "foo", { configurable: false })).toBe(o);
expect(() => {
Object.defineProperty(o, "foo", { configurable: true });
}).toThrowWithMessage(
TypeError,
"Cannot change attributes of non-configurable property 'foo'"
);
});
test("doesn't prevent changing value of existing properties", () => {
const o = { foo: "bar" };
expect(o.foo).toBe("bar");
Object.seal(o);
o.foo = "baz";
expect(o.foo).toBe("baz");
});
// #6469
test("works with indexed properties", () => {
const a = ["foo"];
expect(a[0]).toBe("foo");
Object.seal(a);
a[0] = "bar";
a[1] = "baz";
expect(a[0]).toBe("bar");
expect(a[1]).toBeUndefined();
});
test("works with properties that are already non-configurable", () => {
const o = {};
Object.defineProperty(o, "foo", {
value: "bar",
configurable: false,
writable: true,
enumerable: true,
});
expect(o.foo).toBe("bar");
Object.seal(o);
o.foo = "baz";
expect(o.foo).toBe("baz");
});
});
|