Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mocha-cases

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha-cases

A tiny mocha test case runner. Suited for simple input to output validation tests.

  • 0.1.10
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mocha-cases

A tiny mocha test case runner. Suited for simple input to output validation tests.

MIT npm version David Dependency Badge

NPM NPM

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' },                 // input value
    expected: { text: 'expected output value' },    // expected output value
    error: RangeError,                              // expected error value, instance or class
    runner: function (value, options) {},           // runner specific to this case
    options: {},                                    // options specific to this case
    only: 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
};

function runner(value, options, done) {             // errback runner takes a `done` callback
    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

    • First release.

License

MIT

Author

Amobiz

Keywords

FAQs

Package last updated on 07 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc