# ava-fast-check

> Property based testing for AVA based on fast-check

Latest version **6.0.0** (published 2022-06-15) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ava-fast-check
pnpm add ava-fast-check
yarn add ava-fast-check
bun add ava-fast-check
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2022-06-15 |
| First published | 2018-09-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43 |
| Author | Nicolas DUBIEN |
| Maintainers | ndubien |
| Keywords | ava, generative, property-based testing, testing, quickcheck, fast-check |

## Links

- npm: https://www.npmjs.com/package/ava-fast-check
- Repository: https://github.com/dubzzz/ava-fast-check
- Homepage: https://github.com/dubzzz/ava-fast-check#readme
- Issues: https://github.com/dubzzz/ava-fast-check/issues
- Funding: https://opencollective.com/fast-check
- npm.io page: https://npm.io/package/ava-fast-check

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 6.0.0 (latest) — 2022-06-15
- 5.0.0 — 2022-02-01
- 4.0.2 — 2021-02-12
- 4.0.1 — 2021-01-25
- 4.0.0 — 2020-11-07
- 3.0.0 — 2020-08-10
- 2.0.0 — 2020-07-06
- 1.1.2 — 2019-08-30
- 1.1.1 — 2019-01-02
- 1.1.0 — 2018-11-21
- 1.0.1 — 2018-09-06
- 1.0.0 — 2018-09-06

## README

# Property based testing for AVA based on [fast-check](https://github.com/dubzzz/fast-check/)

[![Build Status](https://github.com/dubzzz/ava-fast-check/workflows/Build%20Status/badge.svg?branch=main)](https://github.com/dubzzz/ava-fast-check/actions)
[![npm version](https://badge.fury.io/js/ava-fast-check.svg)](https://badge.fury.io/js/ava-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:

```bash
npm install --save-dev ava fast-check ava-fast-check
```

## Example

```typescript
import { testProp, fc } from 'ava-fast-check';

// for all a, b, c strings
// b is a substring of a + b + c
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](https://github.com/avajs/ava/blob/main/docs/02-execution-context.md#execution-context-t-argument) for its first parameter, and the value of each arbitrary for the current test case for the rest of the parameters.

`ava-fast-check` supports all of [AVA's assertions](https://github.com/avajs/ava/blob/main/docs/03-assertions.md#assertions) and like AVA, supports synchronous and asynchronous functions, including promises, observables, and callbacks. See [AVA's documentation](https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md#declaring-test) for more information.

## Advanced

### `fast-check` Parameters

`testProp` accepts an optional `fc.Parameters` for forwarding custom parameters to `fast-check` ([more](https://github.com/dubzzz/fast-check/blob/main/documentation/Runners.md#runners)).

### AVA Modifiers

`ava-fast-check` also comes with [`.only`], [`.serial`] [`.skip`], and [`.failing`] modifiers from AVA.

```typescript
import { testProp, fc } from 'ava-fast-check';

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);
});
```

[`.only`]: https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md#running-specific-tests
[`.serial`]: https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md#running-tests-serially
[`.skip`]: https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md#skipping-tests
[`.failing`]: https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md#failing-tests

### AVA `before`/`after` Hooks

`ava-fast-check` exposes AVA's `before`/`after` [hooks]:

```typescript
import { testProp, fc } from 'ava-fast-check';

testProp.before(t => {
  connectToDatabase();
});

testProp(
  // ... omitted for brevity
);

testProp.after(t => {
  closeDatabaseConnection();
});
```

[hooks]: https://github.com/avajs/ava/blob/main/docs/01-writing-tests.md#before--after-hooks

### AVA Execution Context

`ava-fast-check` mirror's AVA's procedure for customizing the test [execution context]:

```typescript
import { fc, testProp as anyTestProp, PropertyTestInterface } from '../src/ava-fast-check';

type TestContext = {
  state: string
};

const testProp = anyTestProp as PropertyTestInterface<TestContext>;

testProp(
  'should reach terminal state',
  [fc.string()],
  (t, received) => {
    // here t is typed as ExecutionContext<TestContext>
    console.log(t.context.state); // logs 'uninitialized'
    // ... omitted for brevity
  }
);
```

[execution context]: https://github.com/avajs/ava/blob/main/docs/02-execution-context.md

## Minimal requirements

| ava-fast-check | AVA                   | fast-check              |
|----------------|-----------------------|-------------------------|
| ^6.0.0         | >=4.0.0               | ^3.0.0                  |
| ^5.0.0         | >=4.0.0               | ^2.0.0<sup>(2)(4)</sup> |
| ^4.0.0         | >=3.9.0<sup>(1)</sup> | ^2.0.0<sup>(2)</sup>    |
| ^3.0.0         | >=3.9.0<sup>(1)</sup> | ^2.0.0<sup>(2)</sup>    |
| ^2.0.0         | >=3.9.0<sup>(1)</sup> | ^1.0.0                  |
| ^1.0.0         | >=0.1.0<sup>(3)</sup> | ^1.0.0                  |

- (1) `ava@>=3.9.0` for [`t.try`](https://github.com/avajs/ava/blob/main/docs/03-assertions.md#trytitle-implementation--macro--macro-args) support
- (2) `fast-check@^2.0.0` for hybrid module support: `commonjs` and `esm` together
- (3) `ava@>=0.1.0` for its Promise support
- (4) Already compatible with `fast-check@^3.0.0` but bump to `6.0.0` for updated peer version

---
_Source: https://npm.io/package/ava-fast-check · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
