import "mocha"; import { expect } from "chai"; import { is, numbers, objects, funcs } from "../helpers"; describe('Thunk factory "is.instanceOf"', () => { const Thing = class {}; const thing = new Thing(); it("recognizes instances of a class and/or its derived ones", () => { const Derived = class extends Thing {}; const valid = [ thing, new Derived() ]; const invalid = [ ...numbers, ...objects, ...funcs, Thing, Derived ]; const thunk = is.instanceOf(Thing); for (const value of valid) expect(thunk(value)).to.be.true; for (const value of invalid) expect(thunk(value)).to.be.false; expect(is.instanceOf(Number)(5)).to.be.false; }); it("accepts any number of type-like arguments", () => { const Another = class {}; const another = new Another(); const thunk = is.instanceOf(Thing, Another); const valid = [ another, thing ]; for (const value of valid) expect(thunk(value)).to.be.true; expect(thunk(new (class {})())).to.be.false; }); });