Skip to content

Instantly share code, notes, and snippets.

@carlmw
Last active December 16, 2015 10:38
Show Gist options
  • Save carlmw/5421164 to your computer and use it in GitHub Desktop.
Save carlmw/5421164 to your computer and use it in GitHub Desktop.
Mocha setup
(function (global) {
var sandbox,
sinon = require('sinon');
global.should = require('chai').should();
global.expect = require('chai').expect;
require('sinon-mocha').enhance(sinon);
require('chai').use(require('sinon-chai'));
setGlobals();
beforeEach(function() {
sandbox = sinon.sandbox.create();
global.mock = wrap(sandbox, 'mock');
global.stub = wrap(sandbox, 'stub');
Object.prototype.receives = function (name) {
return sandbox.mock(this).expects(name);
};
});
afterEach(function() {
sandbox.restore();
setGlobals();
});
function setGlobals () {
global.mock = sinon.mock;
global.stub = sinon.stub;
delete Object.prototype.receives;
}
function wrap(sandbox, method) {
return function (object, name) {
return sandbox[method](object, name);
};
}
})(global);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment