1.0.1 • Published 5 years ago

jest-function v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

jest-function

Delightful function testing.

NPM Version Downloads Stats

Installation

npm install --save-dev jest-function

Usage

import { check } from "jest-function";

function length(s: string): number {
  return s.length;
}

it(`length`, () => {
  check(length).against([
    { in: "", out: 0 },
    { in: "hello", out: 5 },
  ]);
  // Equivalent:
  expect(length("")).toEqual(0);
  expect(length("hello")).toEqual(5);
});

n-ary functions

function add(a: number, b: number): number {
  return a + b;
}

it(`add`, () => {
  const tuplifiedAdd = (args: [number, number]) => add(...args);
  check(tuplifiedAdd).against([
    { in: [0, 0], out: 0 },
    { in: [2, 5], out: 7 },
  ]);
});

Contribute

npm run verify lints, builds and tests the package.