Possibly empty list laws that must pass for the law set to pass.
Optional
nameOptional 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 LawSet
s that must pass before we run the laws
in this set.
A
LawSet
is a recursive data structure with an array of Laws and an array of baseLawSet
s that models the laws required by some function or datatype. TheLawSet
passes only if all itsLawSet
s 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
andcheckLaws
, 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 forApplicative
and forMonad
. Ineffect-ts
, both extendCovariant
. Thus testing theArray
instance forApplicative
will run the laws forCovariant
. But testing for theMonad
laws will run theCovariant
law tests again. Deduplication avoids this issue.A
LawSet
can be tested by callingtestLaws(lawSet)
inside avitest
suite, 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
.