@amirsavand/unit-test

Unit-testing in the dumbest and simplest way possible.

npm

Installation

npm install --save-dev @amirsavand/unit-test

Usage

This is the main file that runs the tests (index.spec.ts) and it imports other tests.

import './my-class.spec';
import './get-abcd.spec';
import './foo-bar.spec';

import { results } from './results';

results();

Now you can write your tests, here's an example.

import { Assert, Test, TestGroup } from '@amirsavand/unit-test';
import { MyClass } from './my-class'

new TestGroup('MyClass', [
  new Test('should instantiate', (assert: Assert) => {
    const instante = new MyClass();
    assert.defined(instante);
  }),
  new Test('should calculate correctly', (assert: Assert) => {
    const instante = new MyClass();
    assert.equal(instante.calculate(), 25);
  }),
]);

All you have to do now is execute the main file.

# Build your TypeScript file (for TypeScript projects)
tsc -p tsconfig.spec.json src/index.spec.ts
# Execute the file via Node.js
node dist/index.spec.js

Built With

About

Made with 💖 by Savand Bros © 2023-present.