Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

fast-check

Package Overview
Dependencies
Maintainers
1
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-check

Property based testing framework for JavaScript (like QuickCheck)

  • 2.15.1
  • legacy
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
decreased by-15.35%
Maintainers
1
Weekly downloads
Β 
Created

What is fast-check?

fast-check is a property-based testing library for JavaScript and TypeScript. It allows developers to define properties that should hold true for a wide range of inputs, and then automatically generates test cases to verify those properties. This helps in identifying edge cases and ensuring the robustness of the code.

What are fast-check's main functionalities?

Property-based Testing

This feature allows you to define properties that should hold true for a wide range of inputs. In this example, the property being tested is the commutativity of addition.

const fc = require('fast-check');

fc.assert(
  fc.property(fc.integer(), fc.integer(), (a, b) => {
    return a + b === b + a;
  })
);

Custom Arbitraries

Custom arbitraries allow you to define complex data structures for your tests. In this example, a custom arbitrary is created that generates objects with a number and a string.

const fc = require('fast-check');

const myArbitrary = fc.tuple(fc.integer(), fc.string()).map(([num, str]) => ({ num, str }));

fc.assert(
  fc.property(myArbitrary, ({ num, str }) => {
    return typeof num === 'number' && typeof str === 'string';
  })
);

Shrinkable Values

Shrinkable values help in minimizing the size of failing test cases to make debugging easier. In this example, if the property fails, fast-check will try to find the smallest array that causes the failure.

const fc = require('fast-check');

fc.assert(
  fc.property(fc.array(fc.integer()), (arr) => {
    return arr.length < 100;
  }),
  { verbose: true }
);

Other packages similar to fast-check

Keywords

FAQs

Package last updated on 23 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc