npm.io
0.9.16 • Published 6 years ago

truenit

Licence
MIT
Version
0.9.16
Deps
0
Size
38 kB
Vulns
0
Weekly
0
Stars
1

Truenit

Build Status npm version FOSSA Status

Truenit (/ˈtruːnɪt/) is a lightweight, easy-to-use, dependency-free Javascript unit testing library with a simple, yet powerful API.

When should I use Truenit?

  • You want to execute your tests locally during development with a CLI (command line interface).
  • You want to execute your tests on every save on a continuous integration server.
  • You want to use RequireJS or Node or anything else for your source files.

Installation

truenit is available on npm. To install it and its dependencies, run:

$ npm install truenit --save-dev

Usage

1. Import the library in your test file:
const truenit = require( 'truenit' );
2. Register tests with functions that test your test.
// Registers a test to be tested later so that the output is aligned.
truenit.registerTest( 'Module1', () => {

  // Do whatever tests here with Module1.
  // Example:
  truenit.notOk( 6 === 5, 'message if it fails' );
  
} );

// Registers a test that should throw an error.
truenit.registerThrowTest( 'Module2', () => {

  // Do whatever tests here with Module2 that throws an error.
  // Example:
  truenit.ok( 6 === 5, 'message if it fails' );
  
} );
3. Run the tests and the file.
truenit.start();
4. Enjoy the output.
$ npm test

Testing all...

   Testing Module1...     Passed.
   Testing Module2...     Passed.
   Testing Node...        Passed.
   Testing ScreenView...  Passed.
   Testing Property...    Passed.
   Testing OtherClass...  Passed.
   Testing S...           Passed.
   
 All tests passed!
 
$ _

Individual tests

You can also individually test one at a time:

// Tests immediately when called, but doesn't align the result with other tests.
truenit.test( 'Module1', () => {

  // Do whatever tests here with Module1.
  // Example:
  truenit.notOk( 6 === 5, 'message if it fails' );
  
} );

// Tests immediately that the function errors.
truenit.throws( 'Module2', () => {

  // Do whatever tests here that should error with Module2.
  // Example:
  truenit.ok( 6 === 5, 'will not be called' );
  
} );

Documentation

Get Involved

Contact me via email.

Help improve truenit by creating a New Issue.

Copyright 2019 Brandon Li. All Rights Reserved.  |  See the LICENSE