CodeLenny / ava-fast-check

Property based testing for AVA based on fast-check

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Property based testing for AVA based on fast-check

Build Status npm version

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 for its Promise support
  • fast-check ^1.0.0

About

Property based testing for AVA based on fast-check

License:MIT License


Languages

Language:TypeScript 46.1%Language:JavaScript 34.3%Language:Shell 19.6%