Skip to content

Instantly share code, notes, and snippets.

@peterudo
Created July 5, 2012 11:52
Show Gist options
  • Save peterudo/3053261 to your computer and use it in GitHub Desktop.
Save peterudo/3053261 to your computer and use it in GitHub Desktop.
Buster.js test helper
var config = exports;
// Then add `testHelpers` to the config to include it:
config["Browser tests"] = {
// Your own custom config here....
// ...
// Expose the resources so we can fetch them with ajax
// Bad practice to use it as generic as this?
resources: [
"**/*.*"
],
testHelpers: ["helper.js"]
};
/**
* Fetch resources and attach it to the object
*
* @param {Object} object the object to attach the response to
* @param {Object} resources key, value pairs of key/name and url
*/
function fetch(object, resources) {
var deferreds = [];
$.each(resources, function (key, url) {
var deferred = when.defer();
deferreds.push(deferred.promise);
$.get(url, function (response) {
object[key] = response;
deferred.resolve();
});
});
return when.all(deferreds);
}
buster.testCase("A test case", {
setUp: function () {
return fetch(this, {
'json': './test/_files/data.json',
'document': './test/_files/document.html'
});
},
"a test": function () {
assert(this.json);
assert(this.document);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment