Created
September 12, 2011 09:08
-
-
Save jzaefferer/1210880 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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