QuickCheck library for Javascript using Fantasy-Land

Usage no npm install needed!

<script type="module">
  import fantasyCheck from '';


Fantasy Check

Build Status Dependencies Status


QuickCheck is a form of automated specification testing. Instead of manually writing tests cases like so:

   assert(0 + 1 == 1);
   assert(1 + 1 == 2);
   assert(3 + 3 == 6);

We can just write the assertion algebraically and tell QuickCheck to automatically generate lots of inputs:

       function(n) {
           return n + n == 2 * n;
       function(fail) {
           return "Failed after " + fail.tries + " tries: " + fail.inputs.toString();
       "All tests passed!",


Fantasy Check allows the easy testing of various laws whilst being unit testing framework agnostic.

Assuming you're using Fantasy Identities and a adapter from the adapters package with the unit testing framework.


The functor check has 2 different laws which allow you to test the mapping of tagged types. Note - it should be possible to test functions as well, by providing a map (aka compose) for the function type.

  • Identity
  • Composition
exports.law1 = functor.identity(λ)(Identity.of);
exports.law2 = functor.composition(λ)(Identity.of);

Applicative Functors

The applicative functor check has 4 different laws which allow you to test:

  • Identity
  • Composition
  • Homomorphism
  • Interchange
exports.law1 = functor.identity(λ)(Identity);
exports.law2 = functor.composition(λ)(Identity);
exports.law3 = functor.homomorphism(λ)(Identity);
exports.law4 = functor.interchange(λ)(Identity);


The monad check has 3 different laws which allow you to test:

  • Left Identity
  • Right Identity
  • Associativity
exports.law1 = functor.leftIdentity(λ)(Identity);
exports.law2 = functor.rightIdentity(λ)(Identity);
exports.law3 = functor.associativity(λ)(Identity);



Fantasy Check uses nodeunit for all the tests and because of this there is currently an existing adapter in the library to help with integration between nodeunit and Fantasy Check.


Currently Fantasy Check is using Istanbul for code coverage analysis; you can run the coverage via the following command:

This assumes that you have istanbul installed correctly.

istanbul cover nodeunit -- test/*.js

It should report that the total coverage is at 100% for the whole lib.