0.1.1 • Published 7 years ago
mocha-maybe v0.1.1
Mocha maybe
This module adds the ability to skip unit tests at run-time with the mocha testing framework.
Document pages
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 ) {
done()
} else {
// This will signal to mocha maybe that all the other unit tests using the maybe "it", replacement should be ignored.
This.stop = true
expect(false).to.equal(true)
done()
}
})
})
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").to.be.a("function").that.have.property("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
done()
})
// 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) { })
})
})