Interface Law<Ts>

A paper-thin wrapper over a fast-check property and its runtime configuration adding:

  1. Law ≡ property + assert + test - Testing a law will run the fast-check property inside an assertion inside a vitest test(() => {...}) block. This means you can call testLaw and/or testLaws from inside a describe(() => {...}) block, or even from the top level of your test file, but not inside a test(() => {...}) block.
    • The law can also be checked, instead of tested using checkLaw. This exactly the same as testLaw, except in a pure function that returns the test results without using any vitest blocks.
  2. Laws can be grouped under a single label into LawSet . Useful for testing units that require multiple laws, for example typeclasses. Besides its child laws, a LawSet can includes other LawSets as requirements to be run as a guard before testing its own laws.
  3. A law has a name, just like the fc.Property it is wrapping, but also a field for a note. It is shown only on failure or when the fast-check runtime parameter verbose is true. A law can be converted into a fast-check property and tested.
interface Law<Ts> {
    arbitrary: Arbitrary<Ts>;
    name: string;
    note: string;
    parameters?: Parameters<[Ts]>;
    predicate: Predicate<Ts>;
}

Type Parameters

  • Ts extends UnknownArgs

    Tuple whose elements are the predicate arguments.

Properties

arbitrary: Arbitrary<Ts>

Arbitrary for the arguments tuple of the predicate.

name: string

Law name to be used as test name. You can include a description of the unit under test or anything else you wish to appear in the test name, for example: MyList.map:associative.

note: string

A note shown only on failure or in verbose mode.

parameters?: Parameters<[Ts]>

fast-check configuration parameters.

predicate: Predicate<Ts>

Predicate to be tested. Its arguments will appear in a single tuple.