mocha-wrap
Fluent pluggable interface for easily wrapping describe
, context
, it
, and specify
blocks in Mocha tests.
Example
var wrap = ;var expect = expect; var mockWindow = location: href: 'test/url' ;; var obj = a: 1 ;; ;
Plugins
A mocha-wrap
plugin is a named function that returns a MochaWrapper instance or a descriptor object.
-
A plugin’s function
name
must begin with the string “with”. -
Plugins can be globally registered, or
.use
d ad-hoc. -
.use
requires a plugin function as its first argument; further arguments are passed through to the plugin. -
.extend
requires a non-empty description string, and a descriptor object which may contain a value that is a function, or an array of functions, whose keys correspond to any or all of the supported mocha methods. -
Globally registered plugins,
.use
calls, and.extend
calls can be chained, stored, and reused - each link in the chain creates a new instance of a MochaWrapper. -
A descriptor object may contain any or all of these 5 keys:
-
a
description
string, for use in “describe” and/or “it” (this is required when returning an object) -
beforeEach
: a function, or array of functions, for use in amocha
beforeEach
function -
afterEach
: a function, or array of functions, for use in amocha
afterEach
function -
before
: a function, or array of functions, for use in amocha
before
function -
after
: a function, or array of functions, for use in amocha
after
function
The most common approach will be for a plugin function to return this.extend(description, descriptor)
.
A plugin function must have a name
that starts with “with”, and will be invoked with a receiver (”this” value) of a MochaWrapper instance.
To register a plugin, call the register
function on mocha-wrap
with the plugin function. This should not be done in a reusable module.
module { return this;};
Usage
var wrap = ;wrap; describe…
skip/only
Although mocha has describe.skip
, describe.only
, context.skip
, context.only
, it.skip
, it.only
, specify.skip
, and specify.only
, it is not possible to implement these in mocha-wrap without using ES5 property accessors. Since this project supports ES3, we decided to use .skip().describe
etc rather than forfeit the ability to have skip/only.
Tests
Simply clone the repo, npm install
, and run npm test