Interface LawSet

A LawSet is a recursive data structure with an array of Laws and an array of base LawSets that models the laws required by some function or datatype. The LawSet passes only if all its LawSets and all its own laws pass.

You can try to find counterexamples to a set of laws using the functions checkLaw and checkLaws.

Functions in the ts-effect-laws/test entry point will try to find counterexamples as part of a vitest test.

Laws will be deduplicated in the scope of a run of checkLaw and checkLaws, so that the same law will not run more than once per datatype.

This is required because typeclass laws are arranged in a parallel extends hierarchy to the typeclasses themselves, so that a law could appear multiple times in a test.

Consider for example the law tests for Array. It has instances we wish to check both for Applicative and for Monad. In effect-ts, both extend Covariant. Thus testing the Array instance for Applicative will run the laws for Covariant. But testing for the Monad laws will run the Covariant law tests again. Deduplication avoids this issue.

A LawSet can be tested by calling testLaws(lawSet) inside a vitest suite, and will appear in the test results as a list of tests grouped inside a describe() block, if it has a name, or as a flat list of test blocks if it does not. The function must be imported from effect-ts-laws/vitest.

interface LawSet {
    laws: Law<any>[];
    name?: string;
    sets: LawSet[];
}

Properties

Properties

laws: Law<any>[]

Possibly empty list laws that must pass for the law set to pass.

name?: string

Optional name of unit under test. Runner uses this for describe() block name. If missing, no describe() block is wrapped around child laws.

sets: LawSet[]

Possibly empty list of LawSets that must pass before we run the laws in this set.