Created
January 10, 2013 09:57
-
-
Save nilclass/4500881 to your computer and use it in GitHub Desktop.
proposal: promises for teste
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
// 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