{"id":10867,"library":"fast-check","title":"Property-Based Testing for JavaScript/TypeScript","description":"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.","status":"active","version":"4.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/dubzzz/fast-check","tags":["javascript","property-based testing","end-to-end testing","unit testing","testing","quickcheck","faker","fuzzer","fuzz","typescript"],"install":[{"cmd":"npm install fast-check","lang":"bash","label":"npm"},{"cmd":"yarn add fast-check","lang":"bash","label":"yarn"},{"cmd":"pnpm add fast-check","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const fc = require('fast-check').default;","symbol":"fc","correct":"import fc from 'fast-check';"},{"note":"`assert` and `property` are named exports for core testing logic, typically used alongside `fc`'s default export.","wrong":"import fc, { assert, property } from 'fast-check';","symbol":"assert","correct":"import { assert, property, string } from 'fast-check';"},{"note":"Adapter packages like `@fast-check/vitest` (and `@fast-check/worker`, etc.) are ESM-only since their v0.3.0+ (or equivalent) releases.","wrong":"const { test } = require('@fast-check/vitest');","symbol":"test","correct":"import { test } from '@fast-check/vitest';"}],"quickstart":{"code":"import fc from 'fast-check';\n\n// Code under test\nconst contains = (text, pattern) => text.indexOf(pattern) >= 0;\n\n// Properties\ndescribe('properties', () => {\n  // string text always contains itself\n  it('should always contain itself', () => {\n    fc.assert(fc.property(fc.string(), (text) => contains(text, text)));\n  });\n  // string a + b + c always contains b, whatever the values of a, b and c\n  it('should always contain its substrings', () => {\n    fc.assert(\n      fc.property(fc.string(), fc.string(), fc.string(), (a, b, c) => {\n        // Alternatively: no return statement and direct usage of expect or assert\n        return contains(a + b + c, b);\n      }),\n    );\n  });\n});","lang":"javascript","description":"Demonstrates a basic integration of fast-check with Mocha, defining and asserting properties using arbitrary string generation."},"warnings":[{"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.","message":"Several 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`).","severity":"breaking","affected_versions":">=@fast-check/{worker,poisoning,packaged}/v0.6.0, >=@fast-check/{vitest,ava}/v3.0.0"},{"fix":"Consult the fast-check documentation for the recommended alternatives to `Random::next(n)` and `Random::nextInt()`.","message":"The methods `Random::next(n)` and `Random::nextInt()` have been deprecated. Users should migrate to newer alternatives for random number generation.","severity":"deprecated","affected_versions":">=4.6.0"},{"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.","message":"While 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.","severity":"gotcha","affected_versions":">=4.x (core) combined with >=adapter@v0.3.0/v0.6.0/v3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Review the counterexample provided in the test output (the shrunken inputs) to debug your implementation or refine your property's preconditions.","cause":"A property's predicate function returned `false` for a generated input, indicating a bug in the code under test or the property definition.","error":"Error: Property failed by returning false"},{"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.","cause":"Attempting to use ES module `import` syntax in a CommonJS context, especially common when using ESM-only adapter packages like `@fast-check/vitest`.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}