@fast-check/ava
Bring the power of property based testing framework fast-check
into AVA.
@fast-check/ava
simplifies the integration of fast-check
into AVA testing framework.
Getting Started
Install @fast-check/ava
:
npm install --save-dev @fast-check/ava
In order to work properly, @fast-check/ava
requires ava
to be installed.
Example
import { testProp, fc } from '@fast-check/ava';
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 as its first parameter, and the value of each arbitrary for the current test case for the rest of the parameters.
@fast-check/ava
supports all of AVA's assertions and like AVA, it supports synchronous and asynchronous functions, including promises, observables, and callbacks. See AVA's documentation for more information.
Advanced
fast-check
Parameters
testProp
accepts an optional fc.Parameters
for forwarding custom parameters to fast-check
(more).
import { testProp, fc } from '@fast-check/ava';
testProp(
'should detect the substring',
[fc.string(), fc.string(), fc.string()],
(t, a, b, c) => {
t.true((a + b + c).includes(b));
},
{ numRuns: 10 }
);
AVA Modifiers
@fast-check/ava
also comes with .only
, .serial
.skip
, and .failing
modifiers from AVA.
import { testProp, fc } from '@fast-check/ava';
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.skip('should be skipped', [fc.fullUnicodeString()], (t, text) => {
t.is([...text].length, text.length);
});
AVA before
/after
Hooks
@fast-check/ava
exposes AVA's before
/after
hooks:
import { testProp, fc } from '@fast-check/ava';
testProp.before((t) => {
connectToDatabase();
});
testProp();
testProp.after((t) => {
closeDatabaseConnection();
});
AVA Execution Context
@fast-check/ava
mirror's AVA's procedure for customizing the test execution context:
import { fc, testProp as anyTestProp, PropertyTestInterface } from '@fast-check/ava';
type TestContext = {
state: string;
};
const testProp = anyTestProp as PropertyTestInterface<TestContext>;
testProp('should reach terminal state', [fc.string()], (t, received) => {
console.log(t.context.state);
});
Minimal requirements
@fast-check/ava | AVA | fast-check |
---|
^1.0.0 | >=4.0.0 | ^3.0.0 |