Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created March 2, 2012 14:10
Show Gist options
  • Save jfromaniello/1958582 to your computer and use it in GitHub Desktop.
Save jfromaniello/1958582 to your computer and use it in GitHub Desktop.
/*global sinon, QUnit, test*/
sinon.assert.fail = function (msg) {
QUnit.ok(false, msg);
};
sinon.assert.pass = function (assertion) {
QUnit.ok(true, assertion);
};
sinon.config = {
injectIntoThis: true,
injectInto: null,
properties: ["spy", "stub", "mock", "clock", "sandbox"],
useFakeTimers: false,
useFakeServer: true
};
//sandbox per test
(function (global) {
var qModule = QUnit.module;
var setup = function () { $.extend(this, sinon.sandbox.create(sinon.config)); };
var teardown = function () { this.verifyAndRestore(); }
QUnit.module = global.module = function (name, lifecycle) {
lifecycle = lifecycle || {};
var newlc = {};
newlc.setup = function(){
setup.bind(this)();
lifecycle.setup && lifecycle.setup.bind(this)();
};
newlc.teardown = function(){
teardown.bind(this)();
lifecycle.teardown && lifecycle.teardown.bind(this)();
};
qModule(name, newlc);
};
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment