Created
October 22, 2013 13:39
-
-
Save joshrp/7100941 to your computer and use it in GitHub Desktop.
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
waitForPromise: function(defer, expectations, failureHandle, timeout) { | |
var fired = false, | |
results = false, | |
failure = null; | |
timeout = timeout === undefined ? 10000 : timeout; | |
defer.done(function (r) { | |
fired = true; | |
results = r; | |
}).fail(function (err) { | |
fired = true; | |
failure = err; | |
}); | |
waitsFor(function () { | |
return fired; | |
}, "Promise didn't return", timeout); | |
if (failure !== null) { | |
runs(function () { | |
if (failureHandle != undefined) { | |
failureHandle(failure); | |
} else { | |
throw new Error('Promise Failed with: '+err); | |
} | |
}); | |
} else { | |
runs(function () { | |
expectations(results) | |
}); | |
} | |
}, |
Usage
jasmineHelpers.waitForPromise(initMediator(), function (mediator){
expect(spy).not.toHaveBeenCalled();
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could technically do:
but not sure if it's worth it