cotest
yet another unit test assertion and test runner - small, simple, no dependencies
• Why • What • How • License •
Why
This originated as an attempt to have assertions that are less verbose because assert.notDeepStrictEqual
is ugly.
What
Example
const ct = ct
Features
- Javascript Comparison Operators (
==
,!==
,===
,!===
,<
,<=
,>
,>=
) - Negation (
!
,!!
) - Other symbols for nested object
{==}
: deepEqual!{==}
: notDeepEqual{===}
: strictDeepEqual!{===}
: notStrictDeepEqual
throws
for assert.throws,!throws
for doesNotThrows- Async support
- Skip full test groups or individual assertions with
t.skip()
- Only run selected test group(s) with
t.only()
- Basic test runner to run multiple files and directories
- Compact reporting
- Support only running selected tests for troubleshooting
Limitations
- No nesting of tests
- Limited configuration
How
Installation
In node, from the project root folder type npm i -D cotest
to install.
API
Command Line
cotest file1 directory1 directory2 file2 ...
Test Declaration
cotest(titleString[, testFunction [, message]])
cotest.skip(titleString[, testFunction [, message]])
cotest.only(titleString, testFunction [, message])
if no test function is provided, the test will be marked as skipped
Assertion Declaration
assert(operator, valueToTest, referenceValue[, additional message])
assert.skip(operator, valueToTest, referenceValue[, additional message])
Async use
Test are normally automatically completed after the test function is executed.
Example: cotest('syncTest', function(assert) { /*assertions*/ })
To change this behaviour, add a callback to the test function. This calback must be called to end the test.
Example: cotest('asyncTest', function(assert, done) { /*assertions*/; done()})
An error message can be passed to the done
function.
Example: cotest('asyncTest', function(assert, done) { if (true) done() else done('failed') })
If a callback is declared but not called, the test fails after 1000ms.
To change the default duration: cotest.timeout = 1500
Use in a test file
var co =
package.json
Use in "scripts":
In any of the test files are flagged as priority, only these tests will run.