@fast-check/vitest
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@fast-check/vitest

fast-check logo

Bring the power of property based testing framework fast-check into Vitest. @fast-check/vitest simplifies the integration of fast-check into Vitest.

npm version monthly downloads License


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

Package Sidebar

Install

npm i @fast-check/vitest

Weekly Downloads

4,607

Version

0.1.1

License

MIT

Unpacked Size

24.9 kB

Total Files

21

Last publish

Collaborators

  • ndubien