talira

fast-check

Property-based testing for JavaScript and TypeScript

open sourceMITfree

fast-check is a property-based testing library for JavaScript and TypeScript, in the style of QuickCheck. Instead of hand-picked examples, a test states a property that should always hold, and fast-check generates hundreds of inputs from arbitraries, runs the assertion over them and shrinks any failure to the smallest input that still reproduces it, with a seed to replay it. It works inside any test runner, with companion packages for Jest, Vitest and AVA, and supports model-based testing: random sequences of commands run against the system and a simplified model of it, to check that it follows its state machine, as well as race condition detection and prototype poisoning checks. It's under the MIT licence.

Problems it solves

  • model-based testing that checks my app follows its state machine with random command sequences
  • generate random inputs for my TypeScript unit tests and shrink failures to the smallest case
  • find edge-case bugs my hand-written Jest examples miss
  • fuzz a JavaScript parser to find inputs that crash it
  • catch race conditions in async JavaScript code by trying many orderings

Features

  • property-based tests with generated inputs from built-in arbitraries
  • shrinking of failing cases to a minimal counterexample
  • replay of a failure from its seed and path
  • model-based testing with commands run against a model
  • race condition detection with scheduled async tasks
  • prototype poisoning detection
  • works in any test runner; Jest, Vitest and AVA integrations
  • running predicates in dedicated workers