Registry / testing / fast-check

fast-check

JSON →
library4.7.0jsnpmunverified

fast-check is a property-based testing framework for JavaScript and TypeScript, inspired by Haskell's QuickCheck. It enables developers to define properties about their code and automatically generates diverse inputs to test these properties, identifying edge cases that traditional example-based testing might miss. The current stable version is 4.7.0. The project maintains an active release cadence, with continuous development across its core library and various test runner integrations. Key differentiators include its robust shrinking capabilities, which minimize counterexamples to help pinpoint bugs, an extensive set of built-in arbitrary data generators, and comprehensive TypeScript support. It integrates seamlessly with popular testing frameworks like Mocha, Jest, Vitest, and Ava via dedicated adapter packages, though users should be aware of recent changes in module support for these adapters.

npm install fast-check
INSTALL
IMPORT
SIG · FAST-CHECK
F
fast-check
testingjavascriptv4.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fc
import fc from 'fast-check';
const fc = require('fast-check').default;
The primary way to import the main library. While fast-check itself supports both ESM and CJS in v4, many of its adapter packages are ESM-only.
assert
import { assert, property, string } from 'fast-check';
import fc, { assert, property } from 'fast-check';
`assert` and `property` are named exports for core testing logic, typically used alongside `fc`'s default export.
test
import { test } from '@fast-check/vitest';
const { test } = require('@fast-check/vitest');
Adapter packages like `@fast-check/vitest` (and `@fast-check/worker`, etc.) are ESM-only since their v0.3.0+ (or equivalent) releases.

Demonstrates a basic integration of fast-check with Mocha, defining and asserting properties using arbitrary string generation.

import 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', () => { 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', () => { 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); }), ); }); });
Debug
Known issues
breakingSeveral adapter packages (e.g., `@fast-check/worker`, `@fast-check/vitest`, `@fast-check/poisoning`, `@fast-check/packaged`, `@fast-check/ava`) have dropped CommonJS support and are now ESM-only. If you are using these integrations, you must update your project to use ES modules (`import`/`export`).
fix
Migrate your project to use ES module syntax (e.g., `import { test } from '@fast-check/vitest';`) and ensure your Node.js environment is configured for ESM.
affects: >=@fast-check/{worker,poisoning,packaged}/v0.6.0, >=@fast-check/{vitest,ava}/v3.0.0
deprecatedThe methods `Random::next(n)` and `Random::nextInt()` have been deprecated. Users should migrate to newer alternatives for random number generation.
fix
Consult the fast-check documentation for the recommended alternatives to `Random::next(n)` and `Random::nextInt()`.
affects: >=4.6.0
gotchaWhile the core `fast-check` package in the 4.x series still supports CommonJS (`require()`), many of its ecosystem adapter packages (e.g., for Vitest, Ava, Workers) have moved to ESM-only. This can lead to module resolution issues if mixing CommonJS for `fast-check` and ESM-only adapters.
fix
For consistency and to avoid module conflicts, it is recommended to use ESM throughout your project when integrating with the latest versions of fast-check adapter packages.
affects: >=4.x (core) combined with >=adapter@v0.3.0/v0.6.0/v3.0.0
Errors
Common errors & fixes
Error: Property failed by returning false
A property's predicate function returned `false` for a generated input, indicating a bug in the code under test or the property definition.
fix
Review the counterexample provided in the test output (the shrunken inputs) to debug your implementation or refine your property's preconditions.
SyntaxError: Cannot use import statement outside a module
Attempting to use ES module `import` syntax in a CommonJS context, especially common when using ESM-only adapter packages like `@fast-check/vitest`.
fix
Ensure your file is treated as an ES module (e.g., by using `.mjs` extension, or setting `"type": "module"` in `package.json`) or migrate to using `require()` if the package still supports CJS and you must use CJS.
Upgrade
Version history
4.7.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fast-check — npm install fast-check · libregistry