Property based testing for AVA based on fast-check
Bring the power of property based testing framework fast-check into ava.
ava-fast-check simplifies the integration of fast-check into ava testing framework.
Install ava-fast-check and its peer dependencies:
npm install --save-dev ava fast-check ava-fast-checkconst { testProp, fc } = require("ava-fast-check");
// for all a, b, c strings
// b is a substring of a + b + c
testProp('should detect the substring', [fc.string(), fc.string(), fc.string()], (t, a, b, c) => {
t.true((a + b + c).includes(b));
});The property is passed ava's t argument for its first parameter, and the value of each arbitrary for the current test case for the rest of the parameters.
ava-fast-check supports all of ava's assertions and like ava, supports synchronous and asynchronous functions, including promises, observables, and callbacks. See ava's documentation for more information.
If you want to forward custom parameters to fast-check, testProp accepts an optional fc.Parameters (more).
ava-fast-check also comes with .only, .skip and .failing from ava.
import { testProp, fc } from 'ava-fast-check';
testProp('should replay the test for the seed 4242', [fc.nat(), fc.nat()], (t, a, b) => {
t.is(a + b, b + a);
}, { seed: 4242 });
testProp.failing('should be skipped', [fc.fullUnicodeString()], (t, text) => {
t.is([...text].length, text.length);
});ava >=3.9.0fort.trysupportfast-check ^1.0.0