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 = ;var cases =name: 'should {value.text} equal to {expected.text}' // name of the test,// a string, supports nested value interpolation// or a function, takes test value, expected value and options, and returns a stringvalue: text: 'input value' // input valueexpected: text: 'expected output value' // expected output valueerror: RangeError // expected error value, instance or class{} // runner specific to this caseoptions: {} // options specific to this caseonly: false // run this case only?skip: false // skip this case?errback: false // is the runner using an errback (callback)?name: 'case 2...'...;var options =errback: true // is all test defaults to errback?prefix: '' // prefix to test names;{ // errback runner takes a `done` callback;};
Default pass through runner will be used if no runner provided at all.
One case vs. multiple values vs. one expected
You can use an array of values
with a single expected
value:
;
One case vs. multiple values vs. multiple expected
You can use an array of values
and an array of expected
values, to pair multiple given values and expected values:
;
Or, you can use cases
to specify multiple cases:
;
If your values are simple enougth, you may want to simplify them with a pair of value / expected value for each case:
;
Test
$ npm test
Alternatives
Change Logs
-
2019/02/22 - 0.3.0
- Feature: Allow escaping the brace characters
{
and}
with\\
. - Feature: Allow entries of
cases
be an object.
- Feature: Allow escaping the brace characters
-
2018/01/23 - 0.2.1
- Feature: Accept function for test name
- Feature: Add default pass through runner
-
2018/01/14 - 0.2.0
- NPM: Bump version, update readme and publish to npm.js.
-
2017/12/07 - 0.1.11
- Feature: New format for adding test-cases.
-
2016/01/08 - 0.1.10
- Feature: Allow
error
to be anError
instance, a class or a normal value. - Feature: Allow test case negate
errback
option that enabled by overall options.
- Feature: Allow
-
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 adderrback
option.
- Feature: Deprecate the
-
2016/01/06 - 0.1.8
- Feature: Replace
chai-as-promised
withasync-done
. Now async runner can use callback or return promise, stream or observable.
- Feature: Replace
-
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
- First release.
License
MIT