]> Lady’s Gitweb - Pisces/blobdiff - object.test.js
Polish binary.js a little bit.
[Pisces] / object.test.js
index 2b6cbb8163a43d749199baecde1fa2022fee98b2..efef4d84c5581a20e415f094c68729ea339489ea 100644 (file)
@@ -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", () => {
This page took 0.023197 seconds and 4 git commands to generate.