Skip to content

Instantly share code, notes, and snippets.

@scopevale
Forked from abreckner/waitsForAndRuns.js
Last active August 29, 2015 14:22
Show Gist options
  • Save scopevale/510347afbd76a0b35b26 to your computer and use it in GitHub Desktop.
Save scopevale/510347afbd76a0b35b26 to your computer and use it in GitHub Desktop.
// This is the equivalent of the old waitsFor/runs syntax
// which was removed from Jasmine 2
waitsForAndRuns = function(escapeFunction, runFunction, escapeTime) {
// check the escapeFunction every millisecond so as soon as it is met we can escape the function
var interval = setInterval(function() {
if (escapeFunction()) {
clearMe();
runFunction();
}
}, 1);
// in case we never reach the escapeFunction, we will time out
// at the escapeTime
var timeOut = setTimeout(function() {
clearMe();
runFunction();
}, escapeTime);
// clear the interval and the timeout
function clearMe(){
clearInterval(interval);
clearTimeout(timeOut);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment