Muggle
Muggle is a testing library without magic.
It outputs TAP version 13, and supports any assertion library that throws an AssertionError
Goals
- Predictable and simple behavior
- Simple and readable source code
- Intuitive and small API
- Encourage writing robust and readable tests
- Fully tested
Install
$ npm install muggle-test muggle-assert
Usage
A test passes if its callback finishes execution without throwing an error.
const test = // passing test // failing test
Async functions work exactly the same way! await
is used internally to catch both exceptions and rejections.
const test =
Use an assertion library like muggle-assert to keep tests simple and readable. See its readme for details on its API.
const test =const assert =
Parallel
Tests are run in parallel, so make sure tests don't interfere with each other by changing the same global state.
This makes tests complete faster, but it's also much more predictable to keep tests seperate.
Running tests
To run tests simply execute the file
$ node test.js
and pipe to your favorite tap reporter
$ node test.js | tap-spec
To run in browser use tape-run
$ browserify test.js | tape-run
Assertions
Muggle is compatible with any assertion library that throws an error, but muggle-assert is recommended.
The name
, message
, and stack
properties of errors thrown in a test callback will be printed to the TAP output if they are defined.
The actual
, expected
, and operator
properties from an AssertionError will also be included if defined.
TAP directives
There is also a third parameter opts
for the TAP todo and skip directives
skip
If opts.skip
is truthy, then the test is marked as skipped in the TAP output, and the callback won't be run. If opts.skip
is a string, then it will be output as the explanation.
const test =
TODO
If opts.todo
is truthy, then the test is marked as incomplete in the TAP output. If opts.todo
is a string, then it will be output as the explanation. The test will run normally and output a failing test on errors, but TAP reporters won't count it as a test failure.
const test =