Skip to content

Instantly share code, notes, and snippets.

@jzaefferer
Created September 12, 2011 09:08
Show Gist options
  • Save jzaefferer/1210880 to your computer and use it in GitHub Desktop.
Save jzaefferer/1210880 to your computer and use it in GitHub Desktop.
var testTimeout;
module = function(name, mocks) {
QUnit.module(name, {
setup: function() {
if (mocks) {
if (mocks.setup) {
mocks.setup.apply(this, arguments);
}
$.each(mocks, function(url, mock) {
if (/setup|teardown/.test(url)) {
return;
}
if ( $.type(mock) === "string" ){
$.mockjax({
url: "/_api" + url,
proxy: mock,
responseTime: 1
});
} else {
$.mockjax($.extend(mock,{url: "/_api" + url}));
}
});
}
$.mockjax({
url: "/_api*",
responseTime: 1,
response: function(obj){
var message = "Mockjax caught unmocked API call for url: " + obj.url
if (obj.modelType) {
message += ", from component " + obj.modelType;
}
ok( false, message );
}
});
testTimeout = setTimeout(function() {
equal( true, false, "test timeout (5s)" );
// could involve multiple stop calls, reset
QUnit.config.semaphore = 1;
start();
}, 5000);
},
teardown: function() {
clearTimeout(testTimeout);
$.mockjaxClear();
if (mocks && mocks.teardown) {
mocks.teardown.apply(this, arguments);
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment