npm

Check out our latest tech talk, "JavaScript Supply Chain Security" presented by VP of Security, Adam Baldwin.Watch it here »

@dkh-dev/tape-helper

0.0.1 • Public • Published

TapeHelper

A helper for unit testing with tape.

Examples

Example 1

import test from 'tape';
import TapeHelper from '@dkh-dev/tape-helper';
 
test('Test counter', t => {
    const { counter } = new TapeHelper(t);
    const { expect, count } = counter;
 
    t.plan(3);
 
    // counter.value === 0
 
    // Counts and does an assertion
    expect(1); // counter.value === 1
 
    // Simple counts
    count(); // counter.value === 2
 
    // Both 3 and 4 are ok
    expect([ 3, 4 ]); // counter.value === 3
    expect([ 3, 4 ]); // counter.value === 4
});

Example 2

import test from 'tape';
import TapeHelper from '@dkh-dev/tape-helper';
 
test('Test timer', t => {
    const { timer } = new TapeHelper(t);
    const { expect, reset } = timer;
 
    t.plan(3);
 
    // Should be immediately executed
    expect({ from: 0, to: 20 });
 
    // setTimeout isn't precise
    setTimeout(() => expect({ from: 90, to: 120}), 100);
 
    // Resetting the timer
    setTimeout(reset, 200);
    setTimeout(function () {
        // This should be immediately executed
        //     after resetting the timer
        expect({ from: 0, to: 20 });
    }, 200);
});

install

npm i @dkh-dev/tape-helper

Downloadsweekly downloads

4

version

0.0.1

license

Unlicense

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability