npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fast-check/ava

v2.0.1

Published

Property based testing for AVA based on fast-check

Downloads

58,489

Readme

@fast-check/ava

fast-check logo

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';

// 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 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.

⚠️ WARNING: When relying on @fast-check/ava, returning true or false in your predicates is not taken into account. The library wants assertions or plans to be defined as ava itself does. Nonetheless you can still use primitives such as fc.pre to cut runs at the middle if some invariants are unmeet: the started plan (if any) will just be ignored.

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 }, // Example of parameters
);

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();
// ... omitted for brevity

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) => {
  // here t is typed as ExecutionContext<TestContext>
  console.log(t.context.state); // logs 'uninitialized'
  // ... omitted for brevity
});

Minimal requirements

| @fast-check/ava | AVA | fast-check | | --------------- | ------- | ---------- | | ^2.0.0 | >=4.0.0 | ^3.0.0 | | ^1.0.0 | >=4.0.0 | ^3.0.0 |