Skip to content

Latest commit

 

History

History
130 lines (110 loc) · 3.36 KB

readme.md

File metadata and controls

130 lines (110 loc) · 3.36 KB

pava

Parameterized tests for ava!

Install

$ npm i pava

Usage

import test from 'ava'
import parameterized from 'pava'
import { mySerialize, myDeserialize, myMax } from './my-code.js'

// Writing your test like this...
parameterized(
  test,
  `integer serializing and deserializing`,
  {
    zero: 0,
    negative: -4,
    positive: 5,
    large: 100000,
  },
  (t, integer) => {
    t.is(myDeserialize(mySerialize(integer)), integer)
  },
)

// Is the same as writing it like this!
test(`integer serializing and deserializing - zero`, t => {
  t.is(myDeserialize(mySerialize(0)), 0)
})
test(`integer serializing and deserializing - negative`, t => {
  t.is(myDeserialize(mySerialize(-4)), -4)
})
test(`integer serializing and deserializing - positive`, t => {
  t.is(myDeserialize(mySerialize(5)), 5)
})
test(`integer serializing and deserializing - large`, t => {
  t.is(myDeserialize(mySerialize(100000)), 100000)
})

// And writing your test like this...
parameterized(
  test,
  `integer serializing and deserializing`,
  [0, -4, 5, 100000],
  (t, integer) => {
    t.is(myDeserialize(mySerialize(integer)), integer)
  },
)

// Is the same as writing it like this!
// Note: the titles aren't as nice for large test case objects
test(`integer serializing and deserializing - 0`, t => {
  t.is(myDeserialize(mySerialize(0)), 0)
})
test(`integer serializing and deserializing - -4`, t => {
  t.is(myDeserialize(mySerialize(-4)), -4)
})
test(`integer serializing and deserializing - 5`, t => {
  t.is(myDeserialize(mySerialize(5)), 5)
})
test(`integer serializing and deserializing - 100000`, t => {
  t.is(myDeserialize(mySerialize(100000)), 100000)
})

// Destructure object literals to test functions with multiple parameters!
parameterized(
  test,
  `maximum of two integers`,
  {
    sameInteger: { first: 2, second: 2, expected: 2 },
    twoPositive: { first: 2, second: 3, expected: 3 },
    onePositiveOneNegative: { first: 2, second: -3, expected: 2 },
    twoNegative: { first: -2, second: -3, expected: -2 },
  },
  (t, { first, second, expected }) => {
    t.is(myMax(first, second), expected)
  },
)

// You can also use any ava test interface!
parameterized(test.serial /* ... */)
parameterized(test.failing /* ... */)
parameterized(test.only /* ... */)
parameterized(test.skip /* ... */)
parameterized(test.todo /* ... */)
// etc.

See the type definitions for more documentation.

Contributing

Stars are always welcome!

For bugs and feature requests, please create an issue.

For pull requests, please read the contributing guidelines.

License

Apache 2.0

This is not an official Google product.