Skip to content
Property based testing framework for JavaScript (like QuickCheck) written in TypeScript
TypeScript JavaScript
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.codesandbox 👷 Configure CodeSandbox CI (#481) Nov 13, 2019
.github Create Aug 20, 2019
documentation Add task attribute onto the returned value of scheduleSequence (#492) Dec 8, 2019
example Ability to automatically wrap the tasks resolved by the scheduler (#… Dec 8, 2019
logo Polish logo (#353) May 7, 2019
perf Migrate from tslint to eslint (#440) Oct 8, 2019
prebuild Reduce size of the generated property d.ts Mar 15, 2019
src Add task attribute onto the returned value of scheduleSequence (#492) Dec 8, 2019
test Add task attribute onto the returned value of scheduleSequence (#492) Dec 8, 2019
.eslintignore 🚨 Enable no-unused-vars eslint rule (#474) Nov 7, 2019
.eslintrc.js 🚨 Enable no-unused-vars eslint rule (#474) Nov 7, 2019
.gitignore Add deoptimization flags on 'npm run profile' Oct 10, 2018
.npmignore Enable incremental tsc build (#366) May 16, 2019
.prettierignore Mutually recursive arbitrary builder (#377) Jun 20, 2019
.prettierrc Add prettier configuration Mar 31, 2018
.travis.yml Add tests for typings based on tsd (#464) Nov 6, 2019 Update Nov 27, 2019 🔧 Moving away from npm, switching to yarn (#449) Oct 31, 2019
LICENSE Initial commit Oct 30, 2017 Add `fc.scheduler` arbitrary (#479) Nov 27, 2019
api-extractor.json Documentation site with docsify (#343) Apr 15, 2019
buildTypes.js Publish typings by ts version (for bigint case) Jan 3, 2019
jest.config.js Bump npm dependencies Mar 7, 2019
jest.e2e.config.js Add no regression snapshot tests (#349) May 1, 2019
jest.setup.js Move to jest Dec 19, 2018
jest.unit.config.js Adapt Jest configuration for Node 6 Feb 22, 2019
package.json 1.20.0 Nov 27, 2019
tsconfig.json Enable incremental tsc build (#366) May 16, 2019
tsconfig.publish.json Only put comments inside *.d.ts Mar 15, 2019
tsconfig.publish.types.json Only put comments inside *.d.ts Mar 15, 2019
yarn.lock Add `fc.scheduler` arbitrary (#479) Nov 27, 2019

fast-check logo

Property based testing framework for JavaScript/TypeScript

Build Status npm version total downloads

Coverage Status dependencies Status devDependencies Status Known Vulnerabilities

PRs Welcome License Twitter

Getting started

Hands-on tutorial and definition of Property Based Testing: 🏁 see tutorial. Or directly try it online on our pre-configured CodeSandbox.

Property based testing frameworks check the truthfulness of properties. A property is a statement like: for all (x, y, ...) such as precondition(x, y, ...) holds property(x, y, ...) is true.

Install the module with: yarn add fast-check --dev or npm install fast-check --save-dev

Example of integration in mocha:

const fc = require('fast-check');

// Code under test
const contains = (text, pattern) => text.indexOf(pattern) >= 0;

// Properties
describe('properties', () => {
  // string text always contains itself
  it('should always contain itself', () => {
    fc.assert(, text => contains(text, text)));
  // string a + b + c always contains b, whatever the values of a, b and c
  it('should always contain its substrings', () => {
    fc.assert(, fc.string(), fc.string(), (a,b,c) => contains(a+b+c, b)));

In case of failure, the test raises a red flag. Its output should help you to diagnose what went wrong in your implementation. Example with a failing implementation of contain:

1) should always contain its substrings
    Error: Property failed after 1 tests (seed: 1527422598337, path: 0:0): ["","",""]
    Shrunk 1 time(s)
    Got error: Property failed by returning false

    Hint: Enable verbose mode in order to have the list of all failing values encountered during the run

Integration with other test frameworks: ava, jasmine, jest, mocha and tape.

More examples: simple examples, fuzzing and against various algorithms.

Useful documentations:

Why should I migrate to fast-check?

fast-check has initially been designed in an attempt to cope with limitations I encountered while using other property based testing frameworks designed for JavaScript:

  • Types: strong and up-to-date types - thanks to TypeScript
  • Extendable: easy map method to derive existing arbitraries while keeping shrink [more] - some frameworks ask the user to provide both a->b and b->a mappings in order to keep a shrinker
  • Extendable: kind of flatMap-operation called chain [more] - able to bind the output of an arbitrary as input of another one while keeping the shrink working
  • Extendable: precondition checks with fc.pre(...) [more] - filtering invalid entries can be done directly inside the check function if needed
  • Smart: ability to shrink on fc.oneof [more] - surprisingly some frameworks don't
  • Smart: biased by default [more] - by default it generates both small and large values, making it easier to dig into counterexamples without having to tweak a size parameter manually
  • Debug: verbose mode [more] - easier troubleshooting with verbose mode enabled
  • Debug: replay directly on the minimal counterexample [more] - no need to replay the whole sequence, you get directly the counterexample
  • Debug: custom examples in addition of generated ones [more] - no need to duplicate the code to play the property on custom examples
  • Debug: logger per predicate run [more] - simplify your troubleshoot with fc.context and its logging feature
  • Unique: model based approach [more][article] - use the power of property based testing to test UI, APIs or state machines
  • Unique: detect race conditions in your code [more] - shuffle the way your promises and async calls resolve using the power of property based testing to detect races

For more details, refer to the documentation in the links above.

Issues found by fast-check in famous packages

fast-check has been able to find some unexpected behaviour among famous npm packages. Here are some of the errors detected using fast-check:


Issue detected: enabling !!int: binary style when dumping negative integers produces invalid content [more]

Code example: yaml.dump({toto: -10}, {styles:{'!!int':'binary'}}) produces toto: 0b-1010 not toto: -0b1010


Issue detected: enabling the bracket setting when exporting arrays containing null values produces an invalid output for the parser [more]

Code example:

m.stringify({bar: ['a', null, 'b']}, {arrayFormat: 'bracket'}) //=> "bar[]=a&bar&bar[]=b"
m.parse('bar[]=a&bar&bar[]=b', {arrayFormat: 'bracket'})       //=> {bar: [null, 'b']}

MORE: Issues detected thanks of fast-check

Code Contributors

This project would not be the same without them 💖 - Become one of them

You can’t perform that action at this time.