Created
July 5, 2012 11:52
-
-
Save peterudo/3053261 to your computer and use it in GitHub Desktop.
Buster.js test helper
This file contains 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 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"] | |
}; |
This file contains 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
/** | |
* 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); | |
} |
This file contains 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
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