mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +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,23 +1,33 @@
|
|||
load("test-common.js");
|
||||
test("length is 1", () => {
|
||||
expect(Reflect.preventExtensions).toHaveLength(1);
|
||||
});
|
||||
|
||||
try {
|
||||
assert(Reflect.preventExtensions.length === 1);
|
||||
|
||||
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
|
||||
assertThrowsError(() => {
|
||||
Reflect.preventExtensions(value);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "First argument of Reflect.preventExtensions() must be an object"
|
||||
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");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var o = {};
|
||||
assert(Reflect.isExtensible(o) === true);
|
||||
assert(Reflect.preventExtensions(o) === true);
|
||||
assert(Reflect.isExtensible(o) === false);
|
||||
describe("normal behavior", () => {
|
||||
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();
|
||||
});
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
||||
test("property values can still be changed", () => {
|
||||
// FIXME: This doesn't work even though it should (the value remains unchanged)
|
||||
// var o = {};
|
||||
// o.foo = "foo";
|
||||
// expect(Reflect.preventExtensions(o)).toBeTrue();
|
||||
// o.foo = "bar";
|
||||
// expect(o.foo).toBe("bar");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue