Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including mocha-maybe with all npm packages installed. Try it out:

var mochaMaybe = require("mocha-maybe")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

mocha-maybe v0.1.1

This module adds stop testing functionality to the mocha unit testing framework.

Mocha maybe

This module adds the ability to skip unit tests at run-time with the mocha testing framework.

Document pages

Bash on Windows

Author: Robert Steckroth, Bustout

License: MIT

Below is an example of how to use Mocha maybe in unit tests.

var maybe = require("mocha-maybe"),
    expect = require("chai").expect,
    command_exist = require("command-exists"),
    path = require('path')

describe("Mocha maybe unit testing - "+path.basename(__filename) , function() { 

    // The stop property of the first describe enclosure is used to control test skipping.
    this.stop = false
    var it_might = maybe(this)  

    describe("Checking test file dependencies..", function() { 

        it_might("finds r_js in the system as a program", function(done) {

            // this.stop needs to be de-scoped for use inside the command_exist enclosure.
            var This = this
            command_exist("r_js", function(err, success ) {
                if ( success ) {
                } else {
                    // This will signal to mocha maybe that all the other unit tests using the maybe "it", replacement should be ignored.
                    This.stop = true 

        it_might("has all module dependencies available", function(done) {

            // Signal to stop all other tests first.
            this.stop = true 
            expect(require("requirejs"), "requirejs was not found on system")"function")"config")
            // If the above test succeeds than the signal to stop (this.stop), is turned back off. This commands below will not be reached if the expect
            // call is failed (the test is stopped by mocha).
            this.stop = false 

        // Any and all of the built-in mocha it functionality works the same way.
        //it_might.skip("This is a  skipped test", function(done) { })
        //it_might.only("This is the only test which will run", function(done) { })


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free