fast-check
Property-based testing library for JavaScript and TypeScript that automatically generates test inputs to find edge cases and hidden bugs.
fast-check is a property-based testing framework for JavaScript and TypeScript that automatically generates test inputs instead of relying on manually written examples. It runs user-defined properties over hundreds or thousands of randomized cases and shrinks failing inputs to the smallest reproducible example, making it easier to debug issues.
The library is test-runner agnostic and works with frameworks like Jest, Mocha, Vitest, and others without requiring special integration. It is designed to uncover complex and often overlooked bugs such as edge cases, race conditions, and invalid input combinations by systematically exploring input spaces rather than fixed scenarios.
At its core, fast-check introduces the concept of “properties,” which are assertions that should hold true for all inputs, and “arbitraries,” which are generators responsible for producing random but controlled test data. This allows developers to define behavior rather than examples, improving test coverage with significantly less code.
When a failure is detected, fast-check automatically performs “shrinking,” reducing the failing input to its minimal form to make debugging easier. This makes it especially powerful for diagnosing complex bugs that are hard to reproduce manually.
The library is widely used in both open-source and enterprise projects and has a strong ecosystem of extensions for schema-based generation, type-driven testing, and prototype poisoning detection.
Key features include:
- Property-based testing for JS/TS
- Automatic generation of randomized test inputs
- Shrinking of failing cases to minimal reproducible inputs
- Works with any test runner (Jest, Mocha, Vitest, etc.)
- Large ecosystem of arbitraries and integrations
- Supports async and model-based testing
- Helps detect edge cases, race conditions, and logic bugs
- TypeScript-first design with strong typing support
Common use cases include:
- Testing pure functions and complex business logic
- Validating parsers, encoders, and serializers
- Detecting edge cases missed by example-based tests
- Stress-testing stateful systems and concurrent logic
- Increasing test coverage with fewer test cases
- Improving robustness of APIs and libraries
fast-check is positioned as a more systematic alternative to example-based testing, focusing on correctness over hand-picked inputs by exploring a much wider range of possible execution scenarios.
Comments
0Markdown is supported.