@fast-check/vitest
v0.1.3
Published
Property based testing for Vitest based on fast-check
Downloads
47,363
Maintainers
Readme
@fast-check/vitest
Bring the power of property based testing framework fast-check
into Vitest.
@fast-check/vitest
simplifies the integration of fast-check
into Vitest.
Getting Started
Install @fast-check/vitest
:
npm install --save-dev @fast-check/vitest
In order to work properly, @fast-check/vitest
requires vitest
to be installed.
Example
import { test, fc } from '@fast-check/vitest';
// for all a, b, c strings
// b is a substring of a + b + c
test.prop([fc.string(), fc.string(), fc.string()])('should detect the substring', (a, b, c) => {
return (a + b + c).includes(b);
});
// same property but using named values
test.prop({ a: fc.string(), b: fc.string(), c: fc.string() })('should detect the substring', ({ a, b, c }) => {
return (a + b + c).includes(b);
});
Please note that the properties accepted by @fast-check/vitest
as input can either be synchronous or asynchronous (even just PromiseLike
instances).
Advanced
If you want to forward custom parameters to fast-check, test.prop
accepts an optional fc.Parameters
(more).
@fast-check/vitest
also comes with .only
, .skip
, .todo
and .concurrent
from vitest. It also accepts more complex ones such as .concurrent.skip
.
import { it, test, fc } from '@fast-check/vitest';
test.prop([fc.nat(), fc.nat()], { seed: 4242 })('should replay the test for the seed 4242', (a, b) => {
return a + b === b + a;
});
test.skip.prop([fc.fullUnicodeString()])('should be skipped', (text) => {
return text.length === [...text].length;
});
describe('with it', () => {
it.prop([fc.nat(), fc.nat()])('should run too', (a, b) => {
return a + b === b + a;
});
});
Minimal requirements
| @fast-check/vitest | vitest | fast-check | | ------------------ | -------- | ---------- | | ^0.0.0 | >=0.28.1 | ^3.0.0 |