https://github.com/phenomnomnominal/parameterised
Create parameterised tests from Markdown(ish) tables
https://github.com/phenomnomnominal/parameterised
javascript parameterised testing
Last synced: about 2 months ago
JSON representation
Create parameterised tests from Markdown(ish) tables
- Host: GitHub
- URL: https://github.com/phenomnomnominal/parameterised
- Owner: phenomnomnominal
- License: mit
- Created: 2018-07-21T06:23:00.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-21T06:46:16.000Z (almost 7 years ago)
- Last Synced: 2025-03-17T09:27:30.224Z (2 months ago)
- Topics: javascript, parameterised, testing
- Language: TypeScript
- Size: 17.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @phenomnomnominal/parameterised
[](https://img.shields.io/npm/v/@phenomnomnominal/parameterised.svg)
[](https://codeclimate.com/github/phenomnomnominal/parameterised)
[](https://codeclimate.com/github/phenomnomnominal/parameterised/coverage)A little tool to create parameterised tests from [Markdown(ish) tables](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#tables)!
## Installation
```zsh
npm install @phenomnomnominal/parameterised --save-dev
```## Parameterised testing
When writing unit tests, sometimes it is useful to do something like the following:
```javascript
[
{ a: 1, b: 2, expected: 3 },
{ a: -1, b: 1, expected: 0 },
{ a: 2.5, b: 2.5, expected: 5 }
].forEach(test => {
const { a, b, expected } = test;
assert(a + b === expected);
});
```That works well, but wouldn't it be nice to be able to format that in a slightly more readable way? Enter **`parameterised`**!
```javascript
import { parameterised } from '@phenomnomnominal/parameterised';parameterised`
| a | b | expected |
| 1 | 2 | 3 |
| -1 | 1 | 0 |
| 2.5 | 2.5 | 5 |`.forEach(test => {
const { a, b, expected } = test;
assert(a + b === expected);
});
```## Examples:
**`parameterised`** can handle a bunch of different values:
```javascript
parameterised`| param1 | param2 | param3 |
| 1 | 2 | 3 |
| "hello" | a string | "" |
| {"foo":"bar"} | undefined | NaN |
| ${{ baz: 'qux' }} | Infinity | [0,1,2] |
| ${new Date()} | ${'string'} | 2e2 |
| null | 0.00000001 | ${9**9} |`;
```