0.1.0 • Published 6 years ago

@phenomnomnominal/parameterised v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@phenomnomnominal/parameterised

npm version Code Climate Test Coverage

A little tool to create parameterised tests from Markdown(ish) tables!

Installation

npm install @phenomnomnominal/parameterised --save-dev

Parameterised testing

When writing unit tests, sometimes it is useful to do something like the following:

[
    { 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!

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:

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}   |

`;