Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/TomerAberbach/pava

🚀 Parameterized tests for ava!
https://github.com/TomerAberbach/pava

ava avajs nodejs parameterized parameterized-tests parametric testing testing-library

Last synced: 3 months ago
JSON representation

🚀 Parameterized tests for ava!

Awesome Lists containing this project

README

        


pava



version


CI


minzip size


Parameterized tests for ava!

## Install

```sh
$ npm i pava
```

## Usage

```js
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](https://github.com/TomerAberbach/pava/blob/main/src/index.d.ts)
for more documentation.

## Contributing

Stars are always welcome!

For bugs and feature requests,
[please create an issue](https://github.com/TomerAberbach/pava/issues/new).

For pull requests, please read the
[contributing guidelines](https://github.com/TomerAberbach/pava/blob/main/contributing.md).

## License

[Apache 2.0](https://github.com/TomerAberbach/pava/blob/main/license)

This is not an official Google product.