Skip to content

Instantly share code, notes, and snippets.

@LeonFedotov
Last active December 11, 2015 07:19
Show Gist options
  • Save LeonFedotov/4565843 to your computer and use it in GitHub Desktop.
Save LeonFedotov/4565843 to your computer and use it in GitHub Desktop.
jasmine "it" function fix for async, adding another parameter to support promises and augment waitFor.
(function(){
//jasmine "it" function fix for async, adding another parameter to support promises and augment waitsFor.
var generate_promise = function() {
var promise = {
check_for: false,
waits: function() {
waitsFor(function() {
return promise.check_for;
});
},
done: function() {
this.check_for = true;
}
};
promise.done = promise.done.bind(promise);
return promise;
};
jasmineIt = it;
it = function(message, func) {
var promise = generate_promise(),
callback = function() {
func.call(this, promise.done);
promise.waits.call(this);
};
jasmineIt(message, callback);
};
//usage example:
describe("a test", function() {
it("should do something", function(done/* call this function upon async done */) {
runs(function() {
some_async_function_with_callback(function() {
expect(true).toBe(true);
done();
});
});
});
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment