I'm getting acquainted with Jasmine (http://pivotal.github.com/jasmine/) and found something rather baffling:
it("should be able to send a Ghost Request", function() {
var api = fm.api_wrapper;
api.sendGhostRequest(function(response) {
console.dir('server says: ', response);
});
expect(true).toEqual(false);
});
Fails as expected.
However, moving the expect call inside the callback:
it("should be able to send a Ghost Request", function() {
var api = fm.api_wrapper;
api.sendGhostRequest(function(response) {
console.dir('server says: ', response);
expect(true).toEqual(false);
});
});
Somehow passes :O
After some debugging: api.sendGhostRequest() does an asynchronous ajax request, and jasmine rushes past before the request has completed.
Hence the question:
How do I get jasmine to wait for ajax execution before ascertaining the test result?