Last active
December 11, 2015 07:19
-
-
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.
This file contains 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
(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