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

@fast-check/jest

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fast-check/jest

Property based testing for Jest based on fast-check

  • 1.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
decreased by-29.29%
Maintainers
1
Weekly downloads
 
Created
Source

@fast-check/jest

fast-check logo

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

npm version monthly downloads License


Getting Started

Install @fast-check/jest:

npm install --save-dev @fast-check/jest

In order to work properly, @fast-check/jest requires jest to be installed.

We also highly recommend users to launch their tests using the --show-seed option provided by Jest. It ensures Jest will always print the seed by itself (requires Jest ≥29.2.0).

jest --show-seed

Example

import { testProp, fc } from '@fast-check/jest';

// 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()], (a, b, c) => {
  return (a + b + c).includes(b);
});

Please note that the properties accepted by @fast-check/jest as input can either be synchronous or asynchronous (even just PromiseLike instances).

Advanced

If you want to forward custom parameters to fast-check, testProp accepts an optional fc.Parameters (more).

@fast-check/jest also comes with .only, .skip, .todo and .concurrent from jest. It also accepts more complex ones such as .concurrent.failing or .concurrent.only.failing.

import { itProp, testProp, fc } from '@fast-check/jest';

testProp(
  'should replay the test for the seed 4242',
  [fc.nat(), fc.nat()],
  (a, b) => {
    return a + b === b + a;
  },
  { seed: 4242 }
);

testProp.skip('should be skipped', [fc.fullUnicodeString()], (text) => {
  return text.length === [...text].length;
});

describe('with it', () => {
  itProp('should run too', [fc.nat(), fc.nat()], (a, b) => {
    return a + b === b + a;
  });
});

Minimal requirements

@fast-check/jestjestfast-check
^1.0.0>=26.5.0(1)(2)^3.0.0
  • (1) any version of jest should be greater or equal than 26.5.0 if you are using commonjs
  • (2) in order to use esm build, you may need to enable experimental features of node, see here

Keywords

FAQs

Package last updated on 23 Oct 2022

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