jest-function
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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.

Package Sidebar

Install

npm i jest-function

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

4.83 kB

Total Files

7

Last publish

Collaborators

  • alling