// ♓🌟 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,
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);
});
});
return false;
}
};
- assert(
+ assertStrictEquals(
ordinaryHasInstance(
constructor,
new class extends constructor {}(),
),
+ true,
);
});
});