From: Lady Date: Sat, 22 Jul 2023 07:30:18 +0000 (-0700) Subject: Use strict asserts in function.test.js X-Git-Url: https://git.ladys.computer/Pisces/commitdiff_plain/17702fafba0cc7fb96934968488a668c5bb64b0c?ds=sidebyside;hp=e144b3079639f839551c0f243764fb39ab81604f Use strict asserts in function.test.js Also test to ensure that getters and setters are not constructable. --- diff --git a/function.test.js b/function.test.js index 4cfa85f..17e77e2 100644 --- a/function.test.js +++ b/function.test.js @@ -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 . 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, ); }); });