1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:27:46 +00:00

test-js: Use prettier and format all files

This commit is contained in:
Matthew Olsson 2020-07-05 09:27:00 -07:00 committed by Andreas Kling
parent e532888242
commit 6d58c48c2f
248 changed files with 8291 additions and 7725 deletions

View file

@ -1,39 +1,39 @@
test("length is 3", () => {
expect(Reflect.apply).toHaveLength(3);
expect(Reflect.apply).toHaveLength(3);
});
describe("errors", () => {
test("target must be a function", () => {
[null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => {
expect(() => {
Reflect.apply(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.apply() must be a function");
});
test("target must be a function", () => {
[null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => {
expect(() => {
Reflect.apply(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.apply() must be a function");
});
});
test("arguments list must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.apply(() => {}, undefined, value);
}).toThrowWithMessage(TypeError, "Arguments list must be an object");
});
test("arguments list must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.apply(() => {}, undefined, value);
}).toThrowWithMessage(TypeError, "Arguments list must be an object");
});
});
});
describe("normal behavior", () => {
test("calling built-in functions", () => {
expect(Reflect.apply(String.prototype.charAt, "foo", [0])).toBe("f");
expect(Reflect.apply(Array.prototype.indexOf, ["hello", 123, "foo", "bar"], ["foo"])).toBe(2);
});
test("calling built-in functions", () => {
expect(Reflect.apply(String.prototype.charAt, "foo", [0])).toBe("f");
expect(Reflect.apply(Array.prototype.indexOf, ["hello", 123, "foo", "bar"], ["foo"])).toBe(2);
});
test("|this| argument is forwarded to called function", () => {
function Foo(foo) {
this.foo = foo;
}
test("|this| argument is forwarded to called function", () => {
function Foo(foo) {
this.foo = foo;
}
var o = {};
expect(o.foo).toBeUndefined();
Reflect.apply(Foo, o, ["bar"]);
expect(o.foo).toBe("bar");
});
var o = {};
expect(o.foo).toBeUndefined();
Reflect.apply(Foo, o, ["bar"]);
expect(o.foo).toBe("bar");
});
});

View file

@ -1,69 +1,72 @@
test("length is 2", () => {
expect(Reflect.construct).toHaveLength(2);
expect(Reflect.construct).toHaveLength(2);
});
describe("errors", () => {
test("target must be a function", () => {
[null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => {
expect(() => {
Reflect.construct(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.construct() must be a function");
});
test("target must be a function", () => {
[null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => {
expect(() => {
Reflect.construct(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.construct() must be a function");
});
});
test("arguments list must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.construct(() => {}, value);
}).toThrowWithMessage(TypeError, "Arguments list must be an object");
});
test("arguments list must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.construct(() => {}, value);
}).toThrowWithMessage(TypeError, "Arguments list must be an object");
});
});
test("new target must be a function", () => {
[null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => {
expect(() => {
Reflect.construct(() => {}, [], value);
}).toThrowWithMessage(TypeError, "Optional third argument of Reflect.construct() must be a constructor");
});
test("new target must be a function", () => {
[null, undefined, "foo", 123, NaN, Infinity, {}].forEach(value => {
expect(() => {
Reflect.construct(() => {}, [], value);
}).toThrowWithMessage(
TypeError,
"Optional third argument of Reflect.construct() must be a constructor"
);
});
});
});
describe("normal behavior", () => {
test("built-in Array function", () => {
var a = Reflect.construct(Array, [5]);
expect(a instanceof Array).toBeTrue();
expect(a).toHaveLength(5);
});
test("built-in Array function", () => {
var a = Reflect.construct(Array, [5]);
expect(a instanceof Array).toBeTrue();
expect(a).toHaveLength(5);
});
test("built-in String function", () => {
var s = Reflect.construct(String, [123]);
expect(s instanceof String).toBeTrue();
expect(s).toHaveLength(3);
expect(s.toString()).toBe("123");
});
test("built-in String function", () => {
var s = Reflect.construct(String, [123]);
expect(s instanceof String).toBeTrue();
expect(s).toHaveLength(3);
expect(s.toString()).toBe("123");
});
test("user-defined function", () => {
function Foo() {
this.name = "foo";
}
test("user-defined function", () => {
function Foo() {
this.name = "foo";
}
var o = Reflect.construct(Foo, []);
expect(o.name).toBe("foo");
expect(o instanceof Foo).toBeTrue();
});
var o = Reflect.construct(Foo, []);
expect(o.name).toBe("foo");
expect(o instanceof Foo).toBeTrue();
});
test("user-defined function with different new target", () => {
function Foo() {
this.name = "foo";
}
function Bar() {
this.name = "bar";
}
test("user-defined function with different new target", () => {
function Foo() {
this.name = "foo";
}
var o = Reflect.construct(Foo, [], Bar);
expect(o.name).toBe("foo");
expect(o instanceof Foo).toBeFalse();
expect(o instanceof Bar).toBeTrue();
});
function Bar() {
this.name = "bar";
}
var o = Reflect.construct(Foo, [], Bar);
expect(o.name).toBe("foo");
expect(o instanceof Foo).toBeFalse();
expect(o instanceof Bar).toBeTrue();
});
});

View file

@ -1,74 +1,82 @@
test("length is 3", () => {
expect(Reflect.defineProperty).toHaveLength(3);
expect(Reflect.defineProperty).toHaveLength(3);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.defineProperty(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.defineProperty() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.defineProperty(value);
}).toThrowWithMessage(
TypeError,
"First argument of Reflect.defineProperty() must be an object"
);
});
});
test("descriptor must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.defineProperty({}, "foo", value);
}).toThrowWithMessage(TypeError, "Descriptor argument is not an object");
});
test("descriptor must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.defineProperty({}, "foo", value);
}).toThrowWithMessage(TypeError, "Descriptor argument is not an object");
});
});
});
describe("normal behavior", () => {
test("initial value and non-writable", () => {
var o = {};
test("initial value and non-writable", () => {
var o = {};
expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, writable: false })).toBeTrue();
expect(o.foo).toBe(1);
o.foo = 2;
expect(o.foo).toBe(1);
});
expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, writable: false })).toBeTrue();
expect(o.foo).toBe(1);
o.foo = 2;
expect(o.foo).toBe(1);
});
test("initial value and writable", () => {
var o = {};
test("initial value and writable", () => {
var o = {};
expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, writable: true })).toBeTrue();
expect(o.foo).toBe(1);
o.foo = 2;
expect(o.foo).toBe(2);
});
expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, writable: true })).toBeTrue();
expect(o.foo).toBe(1);
o.foo = 2;
expect(o.foo).toBe(2);
});
test("can redefine value of configurable, writable property", () => {
var o = {};
test("can redefine value of configurable, writable property", () => {
var o = {};
expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true })).toBeTrue();
expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
expect(o.foo).toBe(2);
});
expect(o.foo).toBeUndefined();
expect(
Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true })
).toBeTrue();
expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
expect(o.foo).toBe(2);
});
test("can redefine value of configurable, non-writable property", () => {
var o = {};
test("can redefine value of configurable, non-writable property", () => {
var o = {};
expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false })).toBeTrue();
expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
expect(o.foo).toBe(2);
});
expect(o.foo).toBeUndefined();
expect(
Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false })
).toBeTrue();
expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue();
expect(o.foo).toBe(2);
});
test("cannot redefine value of non-configurable, non-writable property", () => {
var o = {};
test("cannot redefine value of non-configurable, non-writable property", () => {
var o = {};
expect(o.foo).toBeUndefined();
expect(Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false })).toBeTrue();
expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse();
expect(o.foo).toBe(1);
});
expect(o.foo).toBeUndefined();
expect(
Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false })
).toBeTrue();
expect(o.foo).toBe(1);
expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse();
expect(o.foo).toBe(1);
});
});

View file

@ -1,63 +1,66 @@
test("length is 2", () => {
expect(Reflect.deleteProperty).toHaveLength(2);
expect(Reflect.deleteProperty).toHaveLength(2);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.deleteProperty(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.deleteProperty() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.deleteProperty(value);
}).toThrowWithMessage(
TypeError,
"First argument of Reflect.deleteProperty() must be an object"
);
});
});
});
describe("normal behavior", () => {
test("deleting non-existent property", () => {
expect(Reflect.deleteProperty({})).toBeTrue();
expect(Reflect.deleteProperty({}, "foo")).toBeTrue();
});
test("deleting non-existent property", () => {
expect(Reflect.deleteProperty({})).toBeTrue();
expect(Reflect.deleteProperty({}, "foo")).toBeTrue();
});
test("deleting existent property", () => {
var o = { foo: 1 };
expect(o.foo).toBe(1);
expect(Reflect.deleteProperty(o, "foo")).toBeTrue();
expect(o.foo).toBeUndefined();
expect(Reflect.deleteProperty(o, "foo")).toBeTrue();
expect(o.foo).toBeUndefined();
});
test("deleting existent property", () => {
var o = { foo: 1 };
expect(o.foo).toBe(1);
expect(Reflect.deleteProperty(o, "foo")).toBeTrue();
expect(o.foo).toBeUndefined();
expect(Reflect.deleteProperty(o, "foo")).toBeTrue();
expect(o.foo).toBeUndefined();
});
test("deleting existent, configurable, non-writable property", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: true, writable: false });
expect(Reflect.deleteProperty(o, "foo")).toBeTrue();
expect(o.foo).toBeUndefined();
});
test("deleting existent, configurable, non-writable property", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: true, writable: false });
expect(Reflect.deleteProperty(o, "foo")).toBeTrue();
expect(o.foo).toBeUndefined();
});
test("deleting existent, non-configurable, writable property", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: true });
expect(Reflect.deleteProperty(o, "foo")).toBeFalse();
expect(o.foo).toBe(1);
});
test("deleting existent, non-configurable, writable property", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: true });
expect(Reflect.deleteProperty(o, "foo")).toBeFalse();
expect(o.foo).toBe(1);
});
test("deleting existent, non-configurable, non-writable property", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: false });
expect(Reflect.deleteProperty(o, "foo")).toBeFalse();
expect(o.foo).toBe(1);
});
test("deleting existent, non-configurable, non-writable property", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: false });
expect(Reflect.deleteProperty(o, "foo")).toBeFalse();
expect(o.foo).toBe(1);
});
test("deleting array index", () => {
var a = [1, 2, 3];
expect(a).toHaveLength(3);
expect(a[0]).toBe(1);
expect(a[1]).toBe(2);
expect(a[2]).toBe(3);
expect(Reflect.deleteProperty(a, 1)).toBeTrue();
expect(a).toHaveLength(3);
expect(a[0]).toBe(1);
expect(a[1]).toBeUndefined();
expect(a[2]).toBe(3);
});
test("deleting array index", () => {
var a = [1, 2, 3];
expect(a).toHaveLength(3);
expect(a[0]).toBe(1);
expect(a[1]).toBe(2);
expect(a[2]).toBe(3);
expect(Reflect.deleteProperty(a, 1)).toBeTrue();
expect(a).toHaveLength(3);
expect(a[0]).toBe(1);
expect(a[1]).toBeUndefined();
expect(a[2]).toBe(3);
});
});

View file

@ -1,63 +1,63 @@
test("length is 2", () => {
expect(Reflect.get).toHaveLength(2);
expect(Reflect.get).toHaveLength(2);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.get(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.get() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.get(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.get() must be an object");
});
});
});
describe("normal behavior", () => {
test("regular object", () => {
expect(Reflect.get({})).toBeUndefined();
expect(Reflect.get({ undefined: 1 })).toBe(1);
expect(Reflect.get({ foo: 1 })).toBeUndefined();
expect(Reflect.get({ foo: 1 }, "foo")).toBe(1);
});
test("regular object", () => {
expect(Reflect.get({})).toBeUndefined();
expect(Reflect.get({ undefined: 1 })).toBe(1);
expect(Reflect.get({ foo: 1 })).toBeUndefined();
expect(Reflect.get({ foo: 1 }, "foo")).toBe(1);
});
test("array", () => {
expect(Reflect.get([])).toBeUndefined();
expect(Reflect.get([1, 2, 3])).toBeUndefined();
expect(Reflect.get([1, 2, 3], "0")).toBe(1);
expect(Reflect.get([1, 2, 3], 0)).toBe(1);
expect(Reflect.get([1, 2, 3], 1)).toBe(2);
expect(Reflect.get([1, 2, 3], 2)).toBe(3);
expect(Reflect.get([1, 2, 3], 4)).toBeUndefined();
});
test("array", () => {
expect(Reflect.get([])).toBeUndefined();
expect(Reflect.get([1, 2, 3])).toBeUndefined();
expect(Reflect.get([1, 2, 3], "0")).toBe(1);
expect(Reflect.get([1, 2, 3], 0)).toBe(1);
expect(Reflect.get([1, 2, 3], 1)).toBe(2);
expect(Reflect.get([1, 2, 3], 2)).toBe(3);
expect(Reflect.get([1, 2, 3], 4)).toBeUndefined();
});
test("string object", () => {
expect(Reflect.get(new String())).toBeUndefined();
expect(Reflect.get(new String(), 0)).toBeUndefined();
expect(Reflect.get(new String("foo"), "0")).toBe("f");
expect(Reflect.get(new String("foo"), 0)).toBe("f");
expect(Reflect.get(new String("foo"), 1)).toBe("o");
expect(Reflect.get(new String("foo"), 2)).toBe("o");
expect(Reflect.get(new String("foo"), 3)).toBeUndefined();
});
test("string object", () => {
expect(Reflect.get(new String())).toBeUndefined();
expect(Reflect.get(new String(), 0)).toBeUndefined();
expect(Reflect.get(new String("foo"), "0")).toBe("f");
expect(Reflect.get(new String("foo"), 0)).toBe("f");
expect(Reflect.get(new String("foo"), 1)).toBe("o");
expect(Reflect.get(new String("foo"), 2)).toBe("o");
expect(Reflect.get(new String("foo"), 3)).toBeUndefined();
});
test("getter function", () => {
const foo = {
get prop() {
this.getPropCalled = true;
}
};
const bar = {};
Object.setPrototypeOf(bar, foo);
test("getter function", () => {
const foo = {
get prop() {
this.getPropCalled = true;
},
};
const bar = {};
Object.setPrototypeOf(bar, foo);
expect(foo.getPropCalled).toBeUndefined();
expect(bar.getPropCalled).toBeUndefined();
expect(foo.getPropCalled).toBeUndefined();
expect(bar.getPropCalled).toBeUndefined();
Reflect.get(bar, "prop");
expect(foo.getPropCalled).toBeUndefined();
expect(bar.getPropCalled).toBeTrue();
Reflect.get(bar, "prop");
expect(foo.getPropCalled).toBeUndefined();
expect(bar.getPropCalled).toBeTrue();
Reflect.get(bar, "prop", foo);
expect(foo.getPropCalled).toBeTrue();
expect(bar.getPropCalled).toBeTrue();
});
Reflect.get(bar, "prop", foo);
expect(foo.getPropCalled).toBeTrue();
expect(bar.getPropCalled).toBeTrue();
});
});

View file

@ -1,38 +1,41 @@
test("length is 2", () => {
expect(Reflect.getOwnPropertyDescriptor).toHaveLength(2);
expect(Reflect.getOwnPropertyDescriptor).toHaveLength(2);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.getOwnPropertyDescriptor(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.getOwnPropertyDescriptor() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.getOwnPropertyDescriptor(value);
}).toThrowWithMessage(
TypeError,
"First argument of Reflect.getOwnPropertyDescriptor() must be an object"
);
});
});
});
describe("normal behavior", () => {
test("get descriptor of undefined object property", () => {
expect(Reflect.getOwnPropertyDescriptor({})).toBeUndefined();
expect(Reflect.getOwnPropertyDescriptor({}, "foo")).toBeUndefined();
});
test("get descriptor of undefined object property", () => {
expect(Reflect.getOwnPropertyDescriptor({})).toBeUndefined();
expect(Reflect.getOwnPropertyDescriptor({}, "foo")).toBeUndefined();
});
test("get descriptor of defined object property", () => {
var o = { foo: "bar" };
var d = Reflect.getOwnPropertyDescriptor(o, "foo");
expect(d.value).toBe("bar");
expect(d.writable).toBeTrue();
expect(d.enumerable).toBeTrue();
expect(d.configurable).toBeTrue();
});
test("get descriptor of defined object property", () => {
var o = { foo: "bar" };
var d = Reflect.getOwnPropertyDescriptor(o, "foo");
expect(d.value).toBe("bar");
expect(d.writable).toBeTrue();
expect(d.enumerable).toBeTrue();
expect(d.configurable).toBeTrue();
});
test("get descriptor of array length property", () => {
var a = [];
d = Reflect.getOwnPropertyDescriptor(a, "length");
expect(d.value).toBe(0);
expect(d.writable).toBeTrue();
expect(d.enumerable).toBeFalse();
expect(d.configurable).toBeFalse();
});
test("get descriptor of array length property", () => {
var a = [];
d = Reflect.getOwnPropertyDescriptor(a, "length");
expect(d.value).toBe(0);
expect(d.writable).toBeTrue();
expect(d.enumerable).toBeFalse();
expect(d.configurable).toBeFalse();
});
});

View file

@ -1,34 +1,37 @@
test("length is 1", () => {
expect(Reflect.getPrototypeOf).toHaveLength(1);
expect(Reflect.getPrototypeOf).toHaveLength(1);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.getPrototypeOf(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.getPrototypeOf() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.getPrototypeOf(value);
}).toThrowWithMessage(
TypeError,
"First argument of Reflect.getPrototypeOf() must be an object"
);
});
});
});
describe("normal behavior", () => {
test("get prototype of regular object", () => {
expect(Reflect.getPrototypeOf({})).toBe(Object.prototype);
});
test("get prototype of regular object", () => {
expect(Reflect.getPrototypeOf({})).toBe(Object.prototype);
});
test("get prototype of array", () => {
expect(Reflect.getPrototypeOf([])).toBe(Array.prototype);
});
test("get prototype of array", () => {
expect(Reflect.getPrototypeOf([])).toBe(Array.prototype);
});
test("get prototype of string object", () => {
expect(Reflect.getPrototypeOf(new String())).toBe(String.prototype);
});
test("get prototype of string object", () => {
expect(Reflect.getPrototypeOf(new String())).toBe(String.prototype);
});
test("get user-defined prototype of regular object", () => {
var o = {};
var p = { foo: "bar" };
Reflect.setPrototypeOf(o, p);
expect(Reflect.getPrototypeOf(o)).toBe(p);
});
test("get user-defined prototype of regular object", () => {
var o = {};
var p = { foo: "bar" };
Reflect.setPrototypeOf(o, p);
expect(Reflect.getPrototypeOf(o)).toBe(p);
});
});

View file

@ -1,45 +1,45 @@
test("length is 2", () => {
expect(Reflect.has).toHaveLength(2);
expect(Reflect.has).toHaveLength(2);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.has(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.has() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.has(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.has() must be an object");
});
});
});
describe("normal behavior", () => {
test("regular object has property", () => {
expect(Reflect.has({})).toBeFalse();
expect(Reflect.has({ undefined })).toBeTrue();
expect(Reflect.has({ 0: "1" }, "0")).toBeTrue();
expect(Reflect.has({ foo: "bar" }, "foo")).toBeTrue();
expect(Reflect.has({ bar: "baz" }, "foo")).toBeFalse();
expect(Reflect.has({}, "toString")).toBeTrue();
});
test("regular object has property", () => {
expect(Reflect.has({})).toBeFalse();
expect(Reflect.has({ undefined })).toBeTrue();
expect(Reflect.has({ 0: "1" }, "0")).toBeTrue();
expect(Reflect.has({ foo: "bar" }, "foo")).toBeTrue();
expect(Reflect.has({ bar: "baz" }, "foo")).toBeFalse();
expect(Reflect.has({}, "toString")).toBeTrue();
});
test("array has property", () => {
expect(Reflect.has([])).toBeFalse();
expect(Reflect.has([], 0)).toBeFalse();
expect(Reflect.has([1, 2, 3], "0")).toBeTrue();
expect(Reflect.has([1, 2, 3], 0)).toBeTrue();
expect(Reflect.has([1, 2, 3], 1)).toBeTrue();
expect(Reflect.has([1, 2, 3], 2)).toBeTrue();
expect(Reflect.has([1, 2, 3], 3)).toBeFalse();
expect(Reflect.has([], "pop")).toBeTrue();
});
test("array has property", () => {
expect(Reflect.has([])).toBeFalse();
expect(Reflect.has([], 0)).toBeFalse();
expect(Reflect.has([1, 2, 3], "0")).toBeTrue();
expect(Reflect.has([1, 2, 3], 0)).toBeTrue();
expect(Reflect.has([1, 2, 3], 1)).toBeTrue();
expect(Reflect.has([1, 2, 3], 2)).toBeTrue();
expect(Reflect.has([1, 2, 3], 3)).toBeFalse();
expect(Reflect.has([], "pop")).toBeTrue();
});
test("string object has property", () => {
expect(Reflect.has(new String())).toBeFalse();
expect(Reflect.has(new String("foo"), "0")).toBeTrue();
expect(Reflect.has(new String("foo"), 0)).toBeTrue();
expect(Reflect.has(new String("foo"), 1)).toBeTrue();
expect(Reflect.has(new String("foo"), 2)).toBeTrue();
expect(Reflect.has(new String("foo"), 3)).toBeFalse();
expect(Reflect.has(new String("foo"), "charAt")).toBeTrue();
});
test("string object has property", () => {
expect(Reflect.has(new String())).toBeFalse();
expect(Reflect.has(new String("foo"), "0")).toBeTrue();
expect(Reflect.has(new String("foo"), 0)).toBeTrue();
expect(Reflect.has(new String("foo"), 1)).toBeTrue();
expect(Reflect.has(new String("foo"), 2)).toBeTrue();
expect(Reflect.has(new String("foo"), 3)).toBeFalse();
expect(Reflect.has(new String("foo"), "charAt")).toBeTrue();
});
});

View file

@ -1,30 +1,33 @@
test("length is 1", () => {
expect(Reflect.isExtensible).toHaveLength(1);
expect(Reflect.isExtensible).toHaveLength(1);
});
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");
});
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"
);
});
});
});
describe("normal behavior", () => {
test("regular object is extensible", () => {
expect(Reflect.isExtensible({})).toBeTrue();
});
test("regular object is extensible", () => {
expect(Reflect.isExtensible({})).toBeTrue();
});
test("global object is extensible", () => {
expect(Reflect.isExtensible(globalThis)).toBeTrue();
});
test("global object is extensible", () => {
expect(Reflect.isExtensible(globalThis)).toBeTrue();
});
test("regular object is not extensible after preventExtensions()", () => {
var o = {};
expect(Reflect.isExtensible(o)).toBeTrue();
Reflect.preventExtensions(o);
expect(Reflect.isExtensible(o)).toBeFalse();
});
test("regular object is not extensible after preventExtensions()", () => {
var o = {};
expect(Reflect.isExtensible(o)).toBeTrue();
Reflect.preventExtensions(o);
expect(Reflect.isExtensible(o)).toBeFalse();
});
});

View file

@ -1,48 +1,48 @@
test("length is 1", () => {
expect(Reflect.ownKeys).toHaveLength(1);
expect(Reflect.ownKeys).toHaveLength(1);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.ownKeys(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.ownKeys() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.ownKeys(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.ownKeys() must be an object");
});
});
});
describe("normal behavior", () => {
test("regular empty object has no own keys", () => {
var objectOwnKeys = Reflect.ownKeys({});
expect(objectOwnKeys instanceof Array).toBeTrue();
expect(objectOwnKeys).toHaveLength(0);
});
test("regular empty object has no own keys", () => {
var objectOwnKeys = Reflect.ownKeys({});
expect(objectOwnKeys instanceof Array).toBeTrue();
expect(objectOwnKeys).toHaveLength(0);
});
test("regular object with some properties has own keys", () => {
var objectOwnKeys = Reflect.ownKeys({ foo: "bar", bar: "baz", 0: 42 });
expect(objectOwnKeys instanceof Array).toBeTrue();
expect(objectOwnKeys).toHaveLength(3);
expect(objectOwnKeys[0]).toBe("0");
expect(objectOwnKeys[1]).toBe("foo");
expect(objectOwnKeys[2]).toBe("bar");
});
test("regular object with some properties has own keys", () => {
var objectOwnKeys = Reflect.ownKeys({ foo: "bar", bar: "baz", 0: 42 });
expect(objectOwnKeys instanceof Array).toBeTrue();
expect(objectOwnKeys).toHaveLength(3);
expect(objectOwnKeys[0]).toBe("0");
expect(objectOwnKeys[1]).toBe("foo");
expect(objectOwnKeys[2]).toBe("bar");
});
test("empty array has only 'length' own key", () => {
var arrayOwnKeys = Reflect.ownKeys([]);
expect(arrayOwnKeys instanceof Array).toBeTrue();
expect(arrayOwnKeys).toHaveLength(1);
expect(arrayOwnKeys[0]).toBe("length");
});
test("empty array has only 'length' own key", () => {
var arrayOwnKeys = Reflect.ownKeys([]);
expect(arrayOwnKeys instanceof Array).toBeTrue();
expect(arrayOwnKeys).toHaveLength(1);
expect(arrayOwnKeys[0]).toBe("length");
});
test("array with some values has 'lenght' and indices own keys", () => {
var arrayOwnKeys = Reflect.ownKeys(["foo", [], 123, undefined]);
expect(arrayOwnKeys instanceof Array).toBeTrue();
expect(arrayOwnKeys).toHaveLength(5);
expect(arrayOwnKeys[0]).toBe("0");
expect(arrayOwnKeys[1]).toBe("1");
expect(arrayOwnKeys[2]).toBe("2");
expect(arrayOwnKeys[3]).toBe("3");
expect(arrayOwnKeys[4]).toBe("length");
});
test("array with some values has 'lenght' and indices own keys", () => {
var arrayOwnKeys = Reflect.ownKeys(["foo", [], 123, undefined]);
expect(arrayOwnKeys instanceof Array).toBeTrue();
expect(arrayOwnKeys).toHaveLength(5);
expect(arrayOwnKeys[0]).toBe("0");
expect(arrayOwnKeys[1]).toBe("1");
expect(arrayOwnKeys[2]).toBe("2");
expect(arrayOwnKeys[3]).toBe("3");
expect(arrayOwnKeys[4]).toBe("length");
});
});

View file

@ -1,33 +1,36 @@
test("length is 1", () => {
expect(Reflect.preventExtensions).toHaveLength(1);
expect(Reflect.preventExtensions).toHaveLength(1);
});
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");
});
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("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("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("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");
});
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");
});
});

View file

@ -1,96 +1,96 @@
test("length is 3", () => {
expect(Reflect.set).toHaveLength(3);
expect(Reflect.set).toHaveLength(3);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.set(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.set() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.set(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.set() must be an object");
});
});
});
describe("normal behavior", () => {
test("setting properties of regular object", () => {
var o = {};
test("setting properties of regular object", () => {
var o = {};
expect(Reflect.set(o)).toBeTrue();
expect(o.undefined).toBeUndefined();
expect(Reflect.set(o)).toBeTrue();
expect(o.undefined).toBeUndefined();
expect(Reflect.set(o, "foo")).toBeTrue();
expect(o.foo).toBeUndefined();
expect(Reflect.set(o, "foo")).toBeTrue();
expect(o.foo).toBeUndefined();
expect(Reflect.set(o, "foo", "bar")).toBeTrue();
expect(o.foo).toBe("bar");
expect(Reflect.set(o, "foo", "bar")).toBeTrue();
expect(o.foo).toBe("bar");
expect(Reflect.set(o, "foo", 42)).toBeTrue();
expect(o.foo).toBe(42);
});
expect(Reflect.set(o, "foo", 42)).toBeTrue();
expect(o.foo).toBe(42);
});
test("setting configurable, non-writable property of regular object", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: true, writable: false });
expect(Reflect.set(o, "foo", 2)).toBeFalse();
expect(o.foo).toBe(1);
});
test("setting configurable, non-writable property of regular object", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: true, writable: false });
expect(Reflect.set(o, "foo", 2)).toBeFalse();
expect(o.foo).toBe(1);
});
test("setting non-configurable, writable property of regular object", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: true });
expect(Reflect.set(o, "foo", 2)).toBeTrue();
expect(o.foo).toBe(2);
});
test("setting non-configurable, writable property of regular object", () => {
var o = {};
Object.defineProperty(o, "foo", { value: 1, configurable: false, writable: true });
expect(Reflect.set(o, "foo", 2)).toBeTrue();
expect(o.foo).toBe(2);
});
test("", () => {
var a = [];
expect(a.length === 0);
expect(Reflect.set(a, "0")).toBeTrue();
expect(a.length === 1);
expect(a[0]).toBeUndefined();
expect(Reflect.set(a, 1, "foo")).toBeTrue();
expect(a.length === 2);
expect(a[0]).toBeUndefined();
expect(a[1] === "foo");
expect(Reflect.set(a, 4, "bar")).toBeTrue();
expect(a.length === 5);
expect(a[0]).toBeUndefined();
expect(a[1] === "foo");
expect(a[2]).toBeUndefined();
expect(a[3]).toBeUndefined();
expect(a[4] === "bar");
});
test("", () => {
var a = [];
expect(a.length === 0);
expect(Reflect.set(a, "0")).toBeTrue();
expect(a.length === 1);
expect(a[0]).toBeUndefined();
expect(Reflect.set(a, 1, "foo")).toBeTrue();
expect(a.length === 2);
expect(a[0]).toBeUndefined();
expect(a[1] === "foo");
expect(Reflect.set(a, 4, "bar")).toBeTrue();
expect(a.length === 5);
expect(a[0]).toBeUndefined();
expect(a[1] === "foo");
expect(a[2]).toBeUndefined();
expect(a[3]).toBeUndefined();
expect(a[4] === "bar");
});
test("setting setter property of regular object", () => {
const foo = {
set prop(value) {
this.setPropCalled = true;
}
};
expect(foo.setPropCalled).toBeUndefined();
Reflect.set(foo, "prop", 42);
expect(foo.setPropCalled).toBeTrue();
});
test("setting setter property of regular object", () => {
const foo = {
set prop(value) {
this.setPropCalled = true;
},
};
expect(foo.setPropCalled).toBeUndefined();
Reflect.set(foo, "prop", 42);
expect(foo.setPropCalled).toBeTrue();
});
test("setting setter property of regular object with different receiver", () => {
const foo = {
set prop(value) {
this.setPropCalled = true;
}
};
const bar = {};
Object.setPrototypeOf(bar, foo);
expect(foo.setPropCalled).toBeUndefined();
expect(bar.setPropCalled).toBeUndefined();
test("setting setter property of regular object with different receiver", () => {
const foo = {
set prop(value) {
this.setPropCalled = true;
},
};
const bar = {};
Object.setPrototypeOf(bar, foo);
Reflect.set(bar, "prop", 42);
expect(foo.setPropCalled).toBeUndefined();
expect(bar.setPropCalled).toBeTrue();
expect(foo.setPropCalled).toBeUndefined();
expect(bar.setPropCalled).toBeUndefined();
Reflect.set(bar, "prop", 42, foo);
expect(foo.setPropCalled).toBeTrue();
expect(bar.setPropCalled).toBeTrue();
});
Reflect.set(bar, "prop", 42);
expect(foo.setPropCalled).toBeUndefined();
expect(bar.setPropCalled).toBeTrue();
Reflect.set(bar, "prop", 42, foo);
expect(foo.setPropCalled).toBeTrue();
expect(bar.setPropCalled).toBeTrue();
});
});

View file

@ -1,54 +1,57 @@
test("length is 2", () => {
expect(Reflect.setPrototypeOf).toHaveLength(2);
expect(Reflect.setPrototypeOf).toHaveLength(2);
});
describe("errors", () => {
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.setPrototypeOf(value);
}).toThrowWithMessage(TypeError, "First argument of Reflect.setPrototypeOf() must be an object");
});
test("target must be an object", () => {
[null, undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.setPrototypeOf(value);
}).toThrowWithMessage(
TypeError,
"First argument of Reflect.setPrototypeOf() must be an object"
);
});
});
test("prototype must be an object or null", () => {
[undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.setPrototypeOf({}, value);
}).toThrowWithMessage(TypeError, "Prototype must be an object or null");
});
test("prototype must be an object or null", () => {
[undefined, "foo", 123, NaN, Infinity].forEach(value => {
expect(() => {
Reflect.setPrototypeOf({}, value);
}).toThrowWithMessage(TypeError, "Prototype must be an object or null");
});
});
});
describe("normal behavior", () => {
test("setting prototype of regular object", () => {
expect(Reflect.setPrototypeOf({}, null)).toBeTrue();
expect(Reflect.setPrototypeOf({}, {})).toBeTrue();
expect(Reflect.setPrototypeOf({}, Object.prototype)).toBeTrue();
expect(Reflect.setPrototypeOf({}, Array.prototype)).toBeTrue();
expect(Reflect.setPrototypeOf({}, String.prototype)).toBeTrue();
expect(Reflect.setPrototypeOf({}, Reflect.getPrototypeOf({}))).toBeTrue();
});
test("setting prototype of regular object", () => {
expect(Reflect.setPrototypeOf({}, null)).toBeTrue();
expect(Reflect.setPrototypeOf({}, {})).toBeTrue();
expect(Reflect.setPrototypeOf({}, Object.prototype)).toBeTrue();
expect(Reflect.setPrototypeOf({}, Array.prototype)).toBeTrue();
expect(Reflect.setPrototypeOf({}, String.prototype)).toBeTrue();
expect(Reflect.setPrototypeOf({}, Reflect.getPrototypeOf({}))).toBeTrue();
});
test("setting user-defined prototype of regular object", () => {
var o = {};
var p = { foo: "bar" };
expect(o.foo).toBeUndefined();
expect(Reflect.setPrototypeOf(o, p)).toBeTrue();
expect(o.foo).toBe("bar");
});
test("setting user-defined prototype of regular object", () => {
var o = {};
var p = { foo: "bar" };
expect(o.foo).toBeUndefined();
expect(Reflect.setPrototypeOf(o, p)).toBeTrue();
expect(o.foo).toBe("bar");
});
test("setting prototype of non-extensible object", () => {
var o = {};
Reflect.preventExtensions(o);
expect(Reflect.setPrototypeOf(o, {})).toBeFalse();
});
test("setting prototype of non-extensible object", () => {
var o = {};
Reflect.preventExtensions(o);
expect(Reflect.setPrototypeOf(o, {})).toBeFalse();
});
test("setting same prototype of non-extensible object", () => {
var o = {};
var p = { foo: "bar" };
expect(Reflect.setPrototypeOf(o, p)).toBeTrue();
Reflect.preventExtensions(o);
expect(Reflect.setPrototypeOf(o, p)).toBeTrue();
});
test("setting same prototype of non-extensible object", () => {
var o = {};
var p = { foo: "bar" };
expect(Reflect.setPrototypeOf(o, p)).toBeTrue();
Reflect.preventExtensions(o);
expect(Reflect.setPrototypeOf(o, p)).toBeTrue();
});
});