import "mocha"; import { expect } from "chai"; import { is, numbers, choice, ints, floats } from "../helpers"; import { Thunk } from "@valuer/types"; describe('Thunk factory "is.array"', () => { it("recognizes arrays", () => { const thunk = is.array(); const valid = [ numbers, [], "text".split("") ]; const invalid = [ choice(numbers), "text" ]; for (const value of valid) expect(thunk(value)).to.be.true; for (const value of invalid) expect(thunk(value)).to.be.false; }); it("accepts expected array length", () => { const thunk = is.array(5); const valid = [ "abcde".split(""), Array.from({ length: 5 }) ]; const invalid = [ [], "text".split(""), Array.from({ length: 3 }) ] for (const value of valid) expect(thunk(value)).to.be.true; for (const value of invalid) expect(thunk(value)).to.be.false; }); it("accepts item-validating thunk", () => { const thunk = is.array( null, Number.isInteger); expect(thunk(ints)).to.be.true; expect(thunk(floats)).to.be.false; }); });