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

@matttolman/prop-test

v1.1.13

Published

This library provides a property testing framework for JavaScript and TypeScript, as well as fake data generators (e.g. names, credit card info, etc.). The fake data generators integrate with the property testing framework, that way developers can test th

Downloads

2

Readme

Property Testing

This library provides a property testing framework for JavaScript and TypeScript, as well as fake data generators (e.g. names, credit card info, etc.). The fake data generators integrate with the property testing framework, that way developers can test their code with realistic data.

Additionally, this library is set up to be used with existing unit test frameworks (e.g. Jest) rather than providing a separate unit test framework. This allows property testing to be integrated with existing test suites.

Installation

This package is available on npm.

npm i -D @matttolman/prop-test 

Environment Variables

  • PROP_TEST_SEED The seed to use for generating random values
  • PROP_TEST_ITERS The default number of iterations to run for every property (default: 500)
  • PROP_TEST_DATA_VERSION The fake data version to use for generating random values

Usage

The property test framework can be done with any framework which throws an assertion exception when there is a failed assertion. The property test framework will catch those errors, update the message with the sample inputs, automatically perform shrinking, and then rethrow the exception to the wrapping test framework.

If your framework isn't listed here, you should still be able to use the property test framework just fine. Just do your normal test case declaration process, call property('name', ...generators).test(() => { your code }) and have your assertions be in the body of the function passed to the test call.

Jest

Jest is pretty straightforward. It works perfectly inside the it test cases you're used to.

const {property, generators} = require('@mtolman/prop-test')

describe('Math', () => {
    it('can add', () => {
        const intGen = generators.number.ints({min: -1000, max: 1000})

        property('commutative', intGen, intGen)
            .test((a, b) => {
                expect(a + b).toEqual(b + a)
            })

        property('associative', intGen, intGen, intGen)
            .test((a, b, c) => {
                expect((a + b) + c).toEqual(a + (b + c))
            })

        property('identity', intGen)
            .test((a) => {
                expect(a + 0).toEqual(a)
            })
    })
})

Mocha

Mocha is pretty straightforward. Just use it in the it test cases you're used to.

const {property, generators} = require('../../../out/prop-test')
const assert = require('assert');

describe('Math', () => {
    it('can add', () => {
        const intGen = generators.number.ints({min: -1000, max: 1000})

        property('commutative', intGen, intGen)
            .test((a, b) => {
                assert.equal(a + b, b + a)
            })

        property('associative', intGen, intGen, intGen)
            .test((a, b, c) => {
                assert.equal((a + b) + c, a + (b + c))
            })

        property('identity', intGen)
            .test((a) => {
                assert.equal(a + 0, a)
            })
    })
})