must
Version:
Testing and assertion library with friendly BDD syntax — awesome.must.be.true(). Many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good and well tested stuff.
32 lines (24 loc) • 821 B
JavaScript
var wrap = require("lodash.wrap")
var lookupGetter = require("oolong").lookupGetter
exports = module.exports = function(must, promisify) {
must = Object.create(must)
for (var name in must)
if (hasFunction(must, name)) must[name] = promisify(must[name])
Object.defineProperty(must, "assert", {
value: wrap(must.assert, exports.prototype.assert),
configurable: true, writable: true
})
return must
}
exports.prototype.assert = function assert(orig, ok, msg, opts) {
opts = opts ? Object.create(opts) : {}
if ("stack" in this) opts.stack = this.stack
orig.call(this, ok, msg, opts)
}
exports.prototype.then = function(fn, args, actual) {
this.actual = actual
fn.apply(this, args)
}
function hasFunction(obj, name) {
return !lookupGetter(obj, name) && typeof obj[name] == "function"
}