
49

Property based testing support for AVA, based on fast-check
source link: https://www.tuicool.com/articles/hit/q2mEZ3r
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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.
Getting started
Install ava-fast-check
and its peer dependencies:
npm install --save-dev ava fast-check ava-fast-check
Example
import { testProp, fc } from 'ava-fast-check'; // for all a, b, c strings // b is a sustring of a + b + c testProp('should detect the substring', [fc.string(), fc.string(), fc.string()], (a, b, c) => { return (a + b + c).includes(b); });
Please note that the properties accepted by ava-fast-check
as input can either be synchronous or asynchronous (even just PromiseLike
instances).
Advanced
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()], (a, b) => { return a + b === b + a; }, { seed: 4242 }); testProp.failing('should be skipped', [fc.fullUnicodeString()], text => { return text.length === [...text].length; });
Minimal requirements
ava >=0.1.0 fast-check ^1.0.0
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK