Skip to content

Instantly share code, notes, and snippets.

@joshrp
Created October 22, 2013 13:39
Show Gist options
  • Save joshrp/7100941 to your computer and use it in GitHub Desktop.
Save joshrp/7100941 to your computer and use it in GitHub Desktop.
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)
});
}
},
@mrwillihog
Copy link

You could technically do:

}).always(function () {
  fired = true;
});

but not sure if it's worth it

@joshrp
Copy link
Author

joshrp commented Oct 22, 2013

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