]> Lady’s Gitweb - Pisces/commitdiff
Use strict asserts in function.test.js
authorLady <redacted>
Sat, 22 Jul 2023 07:30:18 +0000 (00:30 -0700)
committerLady <redacted>
Mon, 4 Sep 2023 19:40:24 +0000 (15:40 -0400)
Also test to ensure that getters and setters are not constructable.

function.test.js

index 4cfa85fc07605ff1baf1a3e0ac5be1979fa8715d..17e77e24c58ae657a9c2bf025fd87a55def0043f 100644 (file)
@@ -1,14 +1,13 @@
 // ♓🌟 Piscēs ∷ function.test.js
 // ====================================================================
 //
-// Copyright © 2022 Lady [@ Lady’s Computer].
+// Copyright © 2022–2023 Lady [@ Lady’s Computer].
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
 import {
-  assert,
   assertEquals,
   assertStrictEquals,
   describe,
@@ -193,61 +192,113 @@ describe("identity", () => {
 
 describe("isCallable", () => {
   it("[[Call]] returns true for ordinary functions", () => {
-    assert(isCallable(function () {}));
+    assertStrictEquals(isCallable(function () {}), true);
   });
 
   it("[[Call]] returns true for arrow functions", () => {
-    assert(isCallable(() => {}));
+    assertStrictEquals(isCallable(() => {}), true);
   });
 
   it("[[Call]] returns true for generator functions", () => {
-    assert(isCallable(function* () {}));
+    assertStrictEquals(isCallable(function* () {}), true);
   });
 
   it("[[Call]] returns true for classes", () => {
-    assert(isCallable(class {}));
+    assertStrictEquals(isCallable(class {}), true);
   });
 
   it("[[Call]] returns true for builtin functions", () => {
-    assert(isCallable(Math.ceil));
+    assertStrictEquals(isCallable(Math.ceil), true);
+  });
+
+  it("[[Call]] returns true for getters", () => {
+    assertStrictEquals(
+      isCallable(
+        Object.getOwnPropertyDescriptor({
+          get foo() {
+            return undefined;
+          },
+        }, "foo").get,
+      ),
+      true,
+    );
+  });
+
+  it("[[Call]] returns true for setters", () => {
+    assertStrictEquals(
+      isCallable(
+        Object.getOwnPropertyDescriptor({
+          set foo($) {
+            /* do nothing */
+          },
+        }, "foo").set,
+      ),
+      true,
+    );
   });
 
   it("[[Call]] returns false for null", () => {
-    assert(!isCallable(null));
+    assertStrictEquals(isCallable(null), false);
   });
 
   it("[[Call]] returns false for objects", () => {
-    assert(!isCallable({}));
+    assertStrictEquals(isCallable({}), false);
   });
 });
 
 describe("isConstructor", () => {
   it("[[Call]] returns true for ordinary functions", () => {
-    assert(isConstructor(function () {}));
+    assertStrictEquals(isConstructor(function () {}), true);
   });
 
   it("[[Call]] returns false for arrow functions", () => {
-    assert(!isConstructor(() => {}));
+    assertStrictEquals(isConstructor(() => {}), false);
   });
 
   it("[[Call]] returns false for generator functions", () => {
-    assert(!isConstructor(function* () {}));
+    assertStrictEquals(isConstructor(function* () {}), false);
   });
 
   it("[[Call]] returns true for classes", () => {
-    assert(isConstructor(class {}));
+    assertStrictEquals(isConstructor(class {}), true);
   });
 
   it("[[Call]] returns false for builtin functions", () => {
-    assert(!isConstructor(Math.ceil));
+    assertStrictEquals(isConstructor(Math.ceil), false);
+  });
+
+  it("[[Call]] returns false for getters", () => {
+    assertStrictEquals(
+      isConstructor(
+        Object.getOwnPropertyDescriptor({
+          get foo() {
+            return undefined;
+          },
+        }, "foo").get,
+      ),
+      false,
+    );
+  });
+
+  it("[[Call]] returns false for setters", () => {
+    assertStrictEquals(
+      isConstructor(
+        Object.getOwnPropertyDescriptor({
+          set foo($) {
+            /* do nothing */
+          },
+        }, "foo").set,
+      ),
+      false,
+    );
   });
 
   it("[[Call]] returns false for null", () => {
-    assert(!isConstructor(null));
+    assertStrictEquals(isConstructor(null), false);
   });
 
   it("[[Call]] returns false for objects", () => {
-    assert(!isConstructor({}));
+    assertStrictEquals(isConstructor({}), false);
   });
 });
 
@@ -282,11 +333,12 @@ describe("ordinaryHasInstance", () => {
         return false;
       }
     };
-    assert(
+    assertStrictEquals(
       ordinaryHasInstance(
         constructor,
         new class extends constructor {}(),
       ),
+      true,
     );
   });
 });
This page took 0.054244 seconds and 4 git commands to generate.