X-Git-Url: https://git.ladys.computer/Pisces/blobdiff_plain/2edbddced262b90f8422e77fe8ec61a9f8c82e68..b353e413a079066e14c779fc1e203e27ffcd92dd:/object.test.js?ds=inline diff --git a/object.test.js b/object.test.js index 2b6cbb8..efef4d8 100644 --- a/object.test.js +++ b/object.test.js @@ -22,6 +22,10 @@ import { defineOwnProperties, deleteOwnProperty, frozenCopy, + getMethod, + getOwnPropertyKeys, + getPropertyValue, + hasProperty, LazyLoader, PropertyDescriptor, setPropertyValue, @@ -875,6 +879,80 @@ describe("frozenCopy", () => { }); }); +describe("getMethod", () => { + it("[[Call]] gets a method", () => { + const method = () => {}; + assertStrictEquals(getMethod({ method }, "method"), method); + }); + + it("[[Call]] works for values coercible to objects", () => { + assertEquals(getMethod("", "toString"), String.prototype.toString); + }); + + it("[[Call]] throws for null and undefined", () => { + assertThrows(() => getMethod(null, "valueOf")); + assertThrows(() => getMethod(undefined, "valueOf")); + }); + + it("[[Call]] throws if the resulting value isn’t callable", () => { + assertThrows(() => getMethod({ "failure": true }, "failure")); + }); +}); + +describe("getOwnPropertyKeys", () => { + it("[[Call]] gets own (but not inherited) property keys", () => { + assertEquals(getOwnPropertyKeys({ success: true }), ["success"]); + }); + + it("[[Call]] works for values coercible to objects", () => { + assertEquals(getOwnPropertyKeys("foo"), ["0", "1", "2", "length"]); + }); + + it("[[Call]] throws for null and undefined", () => { + assertThrows(() => getOwnPropertyKeys(null)); + assertThrows(() => getOwnPropertyKeys(undefined)); + }); +}); + +describe("getPropertyValue", () => { + it("[[Call]] gets property values on the provided object", () => { + assertStrictEquals( + getPropertyValue({ success: true }, "success"), + true, + ); + }); + + it("[[Call]] works for values coercible to objects", () => { + assertStrictEquals( + getPropertyValue("", "toString"), + String.prototype.toString, + ); + }); + + it("[[Call]] throws for null and undefined", () => { + assertThrows(() => getPropertyValue(null, "valueOf")); + assertThrows(() => getPropertyValue(undefined, "valueOf")); + }); +}); + +describe("hasProperty", () => { + it("[[Call]] gets whether a property exists on the provided object", () => { + assertStrictEquals( + hasProperty({ success: "etaoin" }, "success"), + true, + ); + }); + + it("[[Call]] works for values coercible to objects", () => { + assertStrictEquals(hasProperty("", "toString"), true); + }); + + it("[[Call]] throws for null and undefined", () => { + assertThrows(() => hasProperty(null, "valueOf")); + assertThrows(() => hasProperty(undefined, "valueOf")); + }); +}); + describe("setPropertyValue", () => { it("[[Call]] sets the provided property on the provided object", () => { const obj = {}; @@ -935,9 +1013,9 @@ describe("toObject", () => { assertStrictEquals(toObject(obj), obj); }); - it("returns a new object for nullish values", () => { - assertEquals(toObject(null), {}); - assertEquals(toObject(void {}), {}); + it("throws for nullish values", () => { + assertThrows(() => toObject(null)); + assertThrows(() => toObject(void {})); }); it("returns a wrapper object for other primitives", () => {