@logicos/tinytest
v0.4.1
Published
Minimal testing framework
Downloads
1
Readme
@logicos/tinytest
Minimal testing framework
npm i -D @logicos/tinytest
or
yarn add -D @logicos/tinytest
Purpose
To test conditions, functions, and data structures in a simple and lightweight manner.
This package exposes testing tools for quick logic expectations to the more formal runSpec which allows for testing of sync and async functions simply.
@NOTE: truthy not required, just used as an example :)
How to use { test }
const { test } = require('@logicos/tinytest');
test(something(), somethingElse());
// --> Test has passed!
// or
// --> Test has failed!
test(something(), somethingElse(), 'Something check');
// --> Something check has passed!
// or
// --> Something check has failed!
How to use { runSpec }
const { runSpec } = require('@logicos/tinytest');
runSpec({
name: 'Example of a pass',
test: truthy.validate('foo', 'isFoo'),
expect: true,
});
Example of a pass ✅
runSpec({
name: 'Example of a fail',
test: truthy.validate('foo', 'isBar'),
expect: true,
});
Example of a fail ❌
RunSpec also works with Async
runSpec({
name: 'Function that returns "foo" after some time',
test: truthy.validate(eventuallyFoo(), 'isFoo'),
expect: true,
});
Function that returns "foo" after some time ✅
How to use { btest }
btest only returns a boolean result of your test, no special messages.
btest(truthy.validate(2, 'isEven'), true);
btest(truthy.validate(2, 'isOdd'), true);
btest(truthy.validate(2, 'isOdd'), false);
true
false
true