Nested Parenthetical Madness
    Wondering what’s next for npm?Check out our public roadmap! »

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

    1.0.2 • Public • Published

    Property based testing for Jest based on fast-check

    Build Status npm version

    Bring the power of property based testing framework fast-check into jest. jest-fast-check simplifies the integration of fast-check into jest testing framework.

    Getting started

    Install jest-fast-check and its peer dependencies:

    # With yarn
    yarn add -D jest fast-check jest-fast-check
    
    # With npm
    npm install --save-dev jest fast-check jest-fast-check

    Example

    import { testProp, fc } from "jest-fast-check";
    
    // for all a, b, c strings
    // b is a substring of a + b + c
    testProp(
      "should detect the substring",
      [fc.string(), fc.string(), fc.string()],
      (a, b, c) => {
        return (a + b + c).includes(b);
      }
    );

    Please note that the properties accepted by jest-fast-check as input can either be synchronous or asynchronous (even just PromiseLike instances).

    Advanced

    If you want to forward custom parameters to fast-check, testProp accepts an optional fc.Parameters (more).

    jest-fast-check also comes with .only, .skip and .todo from jest.

    import { itProp, testProp, fc } from "jest-fast-check";
    
    testProp(
      "should replay the test for the seed 4242",
      [fc.nat(), fc.nat()],
      (a, b) => {
        return a + b === b + a;
      },
      { seed: 4242 }
    );
    
    testProp.skip("should be skipped", [fc.fullUnicodeString()], (text) => {
      return text.length === [...text].length;
    });
    
    describe("with it", () => {
      itProp("should run too", [fc.nat(), fc.nat()], (a, b) => {
        return a + b === b + a;
      });
    });

    Minimal requirements

    jest-fast-check jest fast-check
    ^1.0.0 >=26.5.0(1)(2) ^2.0.0(3)
    • (1) any version of jest should be great if you are using commonjs
    • (2) in order to use esm build, you may need to enable experimental features of node, see here
    • (3) fast-check@^2.0.0 for hybrid module support: commonjs and esm together

    Install

    npm i jest-fast-check

    DownloadsWeekly Downloads

    1,075

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    19.2 kB

    Total Files

    11

    Last publish

    Collaborators

    • avatar