2.0.0 • Published 2 years ago

@rachel-barrett/test-js v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

test-js

This is a minimal javascript library for unit testing.

Example Usage

(This example uses typescript, and assumes you have ts-node as a dev dependency, but you could just as easily use javascript with node.)

Save the library to your project as a dev dependency, with:

npm install --save-dev @rachel-barrett/test-js

Create a test directory. Create an index.ts file in it, with contents:

//index.ts

import * as test from "@rachel-barrett/test-js";

import "./TestSuite1";

test.results();

Create a test suite file, also in the test directory e.g.

//TestSuite1.ts

import {group, test, assertEquals} from "@rachel-barrett/test-js";

group(module.filename)(() => {
    group("function foo should:")(() => {
        test("return succes when bar")(() => {
            const expected = 1;
            const actual = 2;

            console.log("log anything helpful for debugging");

            return assertEquals<number>({ expected, actual });
        });
    });
});

Add a test key to your package.json scripts key, that runs:

cd test; ts-node index.ts

Then you can run your tests with:

npm test