mocha-cases
A tiny mocha test case runner. Suited for simple input to output validation tests.
Install
npm install mocha-cases
Usage
One case one value
var test = require('mocha-cases');
var cases = [{
name: 'should {value.text} equal to {expected.text}, supports nested value interpolation',
value: { text: 'input value' },
expected: { text: 'expected output value' },
error: RangeError,
runner: function (value, options) {},
options: {},
only: false,
skip: false,
errback: false
}, {
name: 'case 2...',
...
}];
var options = {
errback: true,
prefix: ''
};
function runner(value, options, done) {
setTimeout(function () {
done(null, 'expected output value');
}, 10);
}
describe('module: mocha-cases', function () {
describe('feature: cases', function () {
test(cases, runner, options);
});
});
One case vs. multiple values vs. one expected
describe('prime number', function () {
test({
name: 'given prime number {value}, isPrime() returns true',
values: [2, 3, 5, 7, 11, 13],
expected: true
}, isPrime);
});
One case vs. multiple values vs. multiple expected
describe('prime number', function () {
test({
name: 'given prime number {value}, isPrime() returns true, false otherwise',
values: [2, 3, 4, 5, 6, 7, 8, 9],
expected: [true, true, false, true, false, true, false, false],
runner: isPrime
});
});
Test
$ npm test
Alternatives
Change Logs
-
2016/01/08 - 0.1.10
- Feature: Allow
error
to be an Error
instance, an class or a normal value. - Feature: Allow test case negate
errback
option that enabled by overall options.
-
2016/01/07 - 0.1.9
- Feature: Deprecate the
async
option. For sync/async runner that returning value, i.e. primitive value, promise, stream or observable, you don't have to add any option. For async runner that use errback (callback), you need to add errback
option.
-
2016/01/06 - 0.1.8
- Feature: Replace
chai-as-promised
with async-done
. Now async runner can use callback or return promise, stream or observable.
-
2015/12/24 - 0.1.6
- NPM: Update npm settings.
-
2015/12/16 - 0.1.5
- Bug Fix: Fix error when expected values array contains falsy value.
-
2015/12/07 - 0.1.4
- NPM: Move mocha from "dependencies" to "peerDependencies".
-
2015/12/03 - 0.1.3
- Feature: Allow multiple values in one case using "values" keyword.
-
2015/12/03 - 0.1.1
- Feature: Make runner optional, or can be defined either in global options or case options.
- Feature: Allow value interpolation in test name.
-
2015/11/23 - 0.1.0
License
MIT
Author
Amobiz