mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:47:35 +00:00
LibJS: Convert Reflect object tests to new testing framework
This commit is contained in:
parent
fc08222f46
commit
46581773c1
14 changed files with 599 additions and 462 deletions
|
@ -1,29 +1,30 @@
|
|||
load("test-common.js");
|
||||
test("length is 1", () => {
|
||||
expect(Reflect.isExtensible).toHaveLength(1);
|
||||
});
|
||||
|
||||
try {
|
||||
assert(Reflect.isExtensible.length === 1);
|
||||
|
||||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
Reflect.isExtensible(value);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "First argument of Reflect.isExtensible() must be an object"
|
||||
describe("errors", () => {
|
||||
test("target must be an object", () => {
|
||||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
expect(() => {
|
||||
Reflect.isExtensible(value);
|
||||
}).toThrowWithMessage(TypeError, "First argument of Reflect.isExtensible() must be an object");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
assert(Reflect.isExtensible({}) === true);
|
||||
describe("normal behavior", () => {
|
||||
test("regular object is extensible", () => {
|
||||
expect(Reflect.isExtensible({})).toBeTrue();
|
||||
});
|
||||
|
||||
var o = {};
|
||||
o.foo = "foo";
|
||||
assert(o.foo === "foo");
|
||||
assert(Reflect.isExtensible(o) === true);
|
||||
Reflect.preventExtensions(o);
|
||||
o.bar = "bar";
|
||||
assert(o.bar === undefined);
|
||||
assert(Reflect.isExtensible(o) === false);
|
||||
test("global object is extensible", () => {
|
||||
expect(Reflect.isExtensible(globalThis)).toBeTrue();
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
test("regular object is not extensible after preventExtensions()", () => {
|
||||
var o = {};
|
||||
expect(Reflect.isExtensible(o)).toBeTrue();
|
||||
Reflect.preventExtensions(o);
|
||||
expect(Reflect.isExtensible(o)).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue