When is fast-check worth adding beside example-based tests?
fast-check works well when a maintainer can state an invariant that should hold across many inputs. It generates examples and tries to shrink a failing input to a smaller counterexample. The quality of the result depends on both the rule and the inputs your generator allows.
Choose a property stronger than a round trip
Suppose a cart merges repeated item codes into one line per item. Total quantity should stay constant, but a buggy function could preserve the total while assigning the quantity to the wrong code. A stronger property compares totals for each code. Generate repeated codes often enough to explore the behaviour you bought the tool to test.
| Generator or property | Failure it can expose | What to inspect |
|---|---|---|
| Repeated item codes | Incorrect merging | At least two lines for the same item occur |
| Per-code quantity conserved | A quantity credited to the wrong item | Expected totals calculated independently |
| Shrunk counterexample | Smallest case reached by shrinking | Can a maintainer reproduce and explain it? |
Keep the smallest useful failure
This desk review follows fast-check’s official getting-started example. During a pilot, deliberately reverse the merge rule for one item code. Record the failing seed and counterexample, then replay it and decide whether to add a named example beside the property. A compact case that a product owner can understand makes the failure easier to maintain.