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

verify-it

v2.3.2

Published

Randomised test property/data generation for NodeJS

Downloads

9,261

Readme

verify-it

Randomised test property/data generation for NodeJS.

JavaScript Style Guide Build Status dependencies Status devDependencies Status

This module provides:

  • Randomised property inputs for testing (delegating the actual testing to a global it or test function).
  • Global verify.it and verify.test functions (which are synonyms).
  • A global verify.describe function (delegating the actual testing to a global describe function).
  • A series of generator functions that can be used to generate properties.
  • Generators are simply functions that produce a value so custom generators are simple to create.

What it is not:

  • A property-based testing framework - each test scenario is only run once with the requested randomised inputs.

Usage

A global it or test function is required for verify-it to delegate testing to (it is used in preference to test). This could be provided by mocha, jest, jasmine or a similar testing framework.

A simple mocha example would be:

require('mocha')
const { Gen } = require('verify-it')

const myGenerator = () => `My custom generated value: ${Math.random()}`

describe('The verify-it library', () => {
  verify.it('should inject randomised properties',
    Gen.string, Gen.object, myGenerator,
    (someString, someObject, someCustomValue) => {
      // Write your tests here in the usual way using the supplied randomised values...
    }
  )

  verify.it('should allow testing of asynchronous callbacks if the test framework supports it', () => {
    Gen.string, Gen.object, myGenerator,
    (someString, someObject, someCustomValue, done) => {
      // Write some more tests here but call the done function when finished
      done()
    }
  )

  verify.describe('when verify.describe is used', Gen.object, (someObject) => {
    verify.it('allows the same generated value to be shared across multiple tests',
      Gen.object, (someOtherObject) => {
        // Write your tests here using both someObject and someOtherObject
      }
    )
  })
})

If your test framework has test.only or it.only and test.skip or test.skip then verify.it.only, verify.test.only, verify.it.skip, and verify.it.skip will also be available. Similarly, if describe.only or describe.skip exist, verify.describe.only and verify.describe.skip will be available.

Generators

Generators are simply functions that produce a value. Several built-in generators are supplied:

const { Gen } = require('verify-it')

| Function | Produces | Notes | |-----------------------------------|-----------|-------| | Gen.word | string | Produces an english word picked at random from a word list. | | Gen.string | string | Produces a random string between 1 and 100 characters in length. | | Gen.stringWithLength(length) | string | Produces a random string with a fixed length. | | Gen.stringNonNumeric | string | Produces a random string that does not contain numeric characters between 1 and 100 characters in length. | | Gen.integer | number | Produces a random integer in the inclusive range between Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER. | | Gen.integerBetween(min, max) | number | Produces a random integer in the inclusive range between min and max. | | Gen.float | number | Produces a random number in the inclusive range between -1E10 and 1E10 | | Gen.floatBetween(min, max) | number | Produces a random number in the inclusive range between min and max | | Gen.object | Object | Produces an object with random word keys and randomised string values. | | Gen.objectWith(...keys) | Object | Produces an object with the supplied keys and randomised string values. | | Gen.error | Error | Produces an Error with a random message string. | | Gen.boolean | boolean | Produces a random boolean value | | Gen.array(generator, length) | Array | Produces an array with length elements (or between 1 and 100 elements if length is omitted) generated using generator. e.g. Gen.array(Gen.string) will produce an array of strings. | | Gen.distinct(generator, length) | Array | Produces an array of length length with distinct values generated using generator. Equality is based on ===. If distinct values cannot be generated after 10 generation attempts, an error will be thrown. | | Gen.pick(values) | any | Picks a random element from the supplied values array. |

Development

  • Install dependencies: yarn install.
  • Run all tests: yarn test.
  • Check dependencies for security vulnerabilities and licensing issues: yarn check-dependencies.

Contributing

See these notes for information for contributors.

License

verify-it is available to all via the Apache-2.0 license.

Copyright © 2017 BBC