Skip to content

Instantly share code, notes, and snippets.

@nilclass
Created January 10, 2013 09:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilclass/4500881 to your computer and use it in GitHub Desktop.
Save nilclass/4500881 to your computer and use it in GitHub Desktop.
proposal: promises for teste
// WITHOUT PROMISES:
tests: [
{
desc: "My async test",
run: function(env) {
var _this = this;
doSomethingThatReturnsAPromise().
then(
function(result) { // SUCCESS HANDLER
// (do some checking of 'result')
// finally:
_this.result(true);
}, function() { // FAILURE HANDLER
_this.result(false);
}
)
}
}
]
// WITH PROMISES
tests: [
{
desc: "My shorter async test",
run: function(env) {
var _this = this;
return doSomethingThatReturnsAPromise().
then(function(result) {
// (do some checks on result, using only _this.xyzAnd functions)
});
}
}
]
// WHAT I THINK WOULD BE NEEDED TO MAKE IT WORK:
// (in the function that runs the test)
// var result = runTheTest.apply(whateverThisIsInTest, [env]);
// if(result && typeof(result.then) === 'function') {
// result.then(function() {
// whateverThisIsInTest.result(true);
// }, function() {
// whateverThisIsInTest.result(false);
// });
// }
// Makes sense?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment