Skip to content

mafumafuultu/testrunner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test runner js

Simple JavaScript test tool

how 2 use

Output the test result to the console (Ctrl + Shift + I OR F12 OR node ~~.js).

const {testRunner, test} = require('./testrunner.js');
testRunner('test group name', () => {
	test('test name', 10).is(10);
});

sample node test.js

Grouping

testRunner(testGroupName, () => {/* tests */});

Test

/**
 * @param testName 'string'
 * @param actor `value` OR `() => value`
 */
test(testName, actor)
test('Test name', 'value') // String
test('Test name', () => [1]) // Array
test('Test name', () => ({obj:0})) // Object
test('Test name', () => 10) // Number

Run

Functions that can be used depend on the type of actor.

.isNull()

test('', actor).isNull(); // actor === null

.isUndefined()

test('', actor).isNull(); // actor === undefined

.likeNull()

test('', actor).isNull(); // actor == null

.is(expect)

/**
 * is
 * @param actor String OR Number OR Array(no sort) OR Object
 * @param expect
 */
test('', actor).is( expect );

.eq(expect)

/**
 * equal
 * @param actor String OR Number OR Array(no sort) OR Object
 * @param expect
 */
test('', actor).eq( expect );

Comparison

/**
 * @param actor Number
 * @param expect
 */
test('', actor).lt( expect );
test('', actor).gt( expect );
test('', actor).le( expect );
test('', actor).ge( expect );

.hasAll(expect)

/**
 * @param actor Array
 * @param expect Array OR value
 */
test('', actor).hasAll(expect);

.isThanRerationsip(mode)

/**
 * Skip in case of NaN
 * [a < b < c < d < e]
 *
 * @param actor Array
 * @param mode '<', '<=', '>', '>='
 */
test('', actor).isThanRerationsip( mode );

Result

// run

testRunner('Test sample', () => {
	test('num_eq_1 a === b', 5).eq(5);
	test('num_eq_2 a === b', 5).eq(20);
	test('not imple test', 'test').lt('test');
});
// console

Running : Test sample
  done : num_eq_1 a === b
  fail : num_eq_2 a === b act : 5 exp : 20
  skip : not imple test StrTest not implements lt

Releases

No releases published

Packages

No packages published