TypeScript Unit Testing tape


tape is minimalistic JavaScript testing framework, it outputs TAP-compliant markup.

To install tape using npm run command

npm install --save-dev tape @types/tape

To use tape with Typescript you need to install ts-node as global package, to do this run command

npm install -g ts-node

Now you are ready to write your first test

import * as test from "tape";

test("Math test", (t) => {
    t.equal(4, 2 + 2);
    t.true(5 > 2 + 2);


To execute test run command

ts-node node_modules/tape/bin/tape math.test.ts

In output you should see

TAP version 13
# Math test
ok 1 should be equal
ok 2 should be truthy

# tests 2
# pass  2

# ok

Good job, you just ran your TypeScript test.

Run multiple test files

You can run multiple test files at once using path wildcards. To execute all Typescript tests in tests directory run command

ts-node node_modules/tape/bin/tape tests/**/*.ts