Possibly empty list laws that must pass for the law set to pass.
OptionalnameOptional name of unit under test. Runner uses this for describe()
block name. If missing, no describe() block is wrapped around
child laws.
Possibly empty list of LawSets that must pass before we run the laws
in this set.
A
LawSetis a recursive data structure with an array of Laws and an array of baseLawSets that models the laws required by some function or datatype. TheLawSetpasses only if all itsLawSets 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/testentry point will try to find counterexamples as part of a vitest test.Laws will be deduplicated in the scope of a run of
checkLawandcheckLaws, so that the same law will not run more than once per datatype.This is required because typeclass laws are arranged in a parallel
extendshierarchy 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 forApplicativeand forMonad. Ineffect-ts, both extendCovariant. Thus testing theArrayinstance forApplicativewill run the laws forCovariant. But testing for theMonadlaws will run theCovariantlaw tests again. Deduplication avoids this issue.A
LawSetcan be tested by callingtestLaws(lawSet)inside avitestsuite, and will appear in the test results as a list of tests grouped inside adescribe()block, if it has a name, or as a flat list of test blocks if it does not. The function must be imported fromeffect-ts-laws/vitest.