Skip to content

Yet another implementation of property based testing framework

License

Notifications You must be signed in to change notification settings

honzabrecka/rapid-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rapid-check CircleCI

Yet another implementation of property based testing framework with support for async properties.

Prerequisities

It's based on async generators, therefore it requires nodejs >=10.

Installation

npm install rapid-check

Usage

Works with any testing framework, here's an example using jest >=23:

const { gen } = require('rapid-check')
const toMatchProperty = require('rapid-check/src/jest.matcher')

expect.extend({ toMatchProperty })

test('Set.has function', async () => {
  const prop = (v) => new Set([1, 2, 3]).has(v)
  await expect(gen.choose(1, 3)).toMatchProperty(prop)
})

Generators

constantly(any)

sample(constantly(4))
// [4, 4, 4, 4, ...]

choose(min, max)

sample(choose(1, 3))
// [2, 1, 3, 1, ...]

bool

sample(bool)
// [true, true, false, true, ...]

int

sample(int)
// [0, 1, -2, 3, ...]

uint

sample(uint)
// [0, 1, 0, 3, ...]

tuple(...gens)

sample(tuple(uint, uint))
// [[0, 0], [1, 0], [1, 2], [0, 1], ...]

array(gen, min, max)

sample(array(uint, 1, 3))
// [[0], [1], [2, 0], [1, 1], [0], [0, 3, 3], ...]

oneOf(...gens)

sample(oneOf(bool, uint))
// [true, 1, 2, false, ...]

fmap(f, gen)

Where f: a -> b

const negate = (n) => -n
sample(fmap(negate, uint))
// [0, -1, -1, -3, ...]

mbind(f, gen)

Where f: a -> Gen b

const f = (n) => ap(tuple, repeat(bool, n))
sample(mbind(f, uint))
// [[], [true], [false, false], [false], ... [true, false, false, true, false], [false]]

About

Yet another implementation of property based testing framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published