blob: 776fc81d3ffca54882288392e6baf7a253527e5a (
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
|
describe("correct behavior", () => {
test("non-object arguments", () => {
expect(Object.preventExtensions()).toBeUndefined();
expect(Object.preventExtensions(undefined)).toBeUndefined();
expect(Object.preventExtensions(null)).toBeNull();
expect(Object.preventExtensions(true)).toBeTrue();
expect(Object.preventExtensions(6)).toBe(6);
expect(Object.preventExtensions("test")).toBe("test");
let s = Symbol();
expect(Object.preventExtensions(s)).toBe(s);
});
test("basic functionality", () => {
let o = { foo: "foo" };
expect(o.foo).toBe("foo");
o.bar = "bar";
expect(o.bar).toBe("bar");
expect(Object.preventExtensions(o)).toBe(o);
expect(o.foo).toBe("foo");
expect(o.bar).toBe("bar");
o.baz = "baz";
expect(o.baz).toBeUndefined();
});
});
describe("errors", () => {
test("defining a property on a non-extensible object", () => {
let o = {};
Object.preventExtensions(o);
expect(() => {
Object.defineProperty(o, "baz", { value: "baz" });
}).toThrowWithMessage(TypeError, "Cannot define property baz on non-extensible object");
expect(o.baz).toBeUndefined();
});
test("putting property on a non-extensible object", () => {
let o = {};
Object.preventExtensions(o);
expect(() => {
"use strict";
o.foo = "foo";
}).toThrowWithMessage(TypeError, "Cannot define property foo on non-extensible object");
expect((o.foo = "foo")).toBe("foo");
expect(o.foo).toBeUndefined();
});
});
|