Property based testing framework for JavaScript (like QuickCheck) written in TypeScript
See the code
Property based testing framework for JavaScript/TypeScript
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 that precondition(x, y, ...) holds predicate(x, y, ...) is true.
Install the module with: pnpm add -D fast-check or yarn add fast-check --dev or npm install fast-check --save-dev
Example of integration in mocha:
import * as fc from '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', async () => {
await fc.assert(fc.property(fc.string(), (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', async () => {
await fc.assert(
fc.property(fc.string(), fc.string(), fc.string(), (a, b, c) => {
// Alternatively: no return statement and direct usage of expect or assert
return 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:
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:
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 shrinkerchain [more] - able to bind the output of an arbitrary as input of another one while keeping the shrink workingfc.pre(...) [more] - filtering invalid entries can be done directly inside the check function if neededfc.gen() [more] - generate random values within your predicatesfc.oneof [more] - surprisingly some frameworks don'tFor more details, refer to the documentation in the links above.
fast-check has been trusted for years by big projects like: jest, jasmine, fp-ts, io-ts, ramda, js-yaml, query-string...
It also proved useful in finding bugs among major open source projects such as jest, query-string... and many others.
Here are the minimal requirements to use fast-check properly without any polyfills:
| fast-check | node | ECMAScript version | TypeScript (optional) |
|---|---|---|---|
| 5.x | β₯22.12.0 | ES2025 | β₯5.8 |
| 4.x | β₯12.17.0(1) | ES2020 | β₯5.0 |
| 3.x | β₯8(2) | ES2017 | β₯4.1(3) |
| 2.x | β₯8(2) | ES2017 | β₯3.2(4) |
| 1.x | β₯0.12(2) | ES3 | β₯3.0(4) |
bigint-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check.@types/node to be installed.@types/node to be installed.Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome! Become one of them
Many individuals and companies offer their financial support to the project, a huge thanks to all of them too π
You can also become one of them by contributing via GitHub Sponsors or OpenCollective.
Overall
Maintained
Code review
Contributors
npm
Latest release
Releases this year
(top 24 of 151)
206 followers Β· starred Mar 2025
1,937 followers Β· starred Feb 2019
1,152 followers Β· starred May 2026
2,546 followers Β· starred Apr 2023
Property based testing framework for JavaScript (like QuickCheck) written in TypeScript
See the code
Property based testing framework for JavaScript/TypeScript
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 that precondition(x, y, ...) holds predicate(x, y, ...) is true.
Install the module with: pnpm add -D fast-check or yarn add fast-check --dev or npm install fast-check --save-dev
Example of integration in mocha:
import * as fc from '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', async () => {
await fc.assert(fc.property(fc.string(), (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', async () => {
await fc.assert(
fc.property(fc.string(), fc.string(), fc.string(), (a, b, c) => {
// Alternatively: no return statement and direct usage of expect or assert
return 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:
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:
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 shrinkerchain [more] - able to bind the output of an arbitrary as input of another one while keeping the shrink workingfc.pre(...) [more] - filtering invalid entries can be done directly inside the check function if neededfc.gen() [more] - generate random values within your predicatesfc.oneof [more] - surprisingly some frameworks don'tFor more details, refer to the documentation in the links above.
fast-check has been trusted for years by big projects like: jest, jasmine, fp-ts, io-ts, ramda, js-yaml, query-string...
It also proved useful in finding bugs among major open source projects such as jest, query-string... and many others.
Here are the minimal requirements to use fast-check properly without any polyfills:
| fast-check | node | ECMAScript version | TypeScript (optional) |
|---|---|---|---|
| 5.x | β₯22.12.0 | ES2025 | β₯5.8 |
| 4.x | β₯12.17.0(1) | ES2020 | β₯5.0 |
| 3.x | β₯8(2) | ES2017 | β₯4.1(3) |
| 2.x | β₯8(2) | ES2017 | β₯3.2(4) |
| 1.x | β₯0.12(2) | ES3 | β₯3.0(4) |
bigint-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check.@types/node to be installed.@types/node to be installed.Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome! Become one of them
Many individuals and companies offer their financial support to the project, a huge thanks to all of them too π
You can also become one of them by contributing via GitHub Sponsors or OpenCollective.
Overall
Maintained
Code review
Contributors
npm
Latest release
Releases this year
(top 24 of 151)
206 followers Β· starred Mar 2025
1,937 followers Β· starred Feb 2019
1,152 followers Β· starred May 2026
2,546 followers Β· starred Apr 2023