This can be done using Jasmine's asyncronous features: waits(), waits For() and runs(): 0; }); runs(function() { expect(callback)Have Been Called(); }); }); function get Product(id, callback) { $.ajax({ type: "GET", url: "data.json", content Type: "application/json; charset=utf-8" data Type: "json", success: callback }); } Look at the jasmine-ajax project:

It's a drop-in helper that (for either j Query or Prototype.js) stubs at the XHR layer so that requests never go out.

You can then expect all you want about the request.

Chat request jasmine-15Chat request jasmine-38

It takes Ajax calls out of the realm of asynchronous tests and provides you a lot of flexibility for testing how your actual response handlers should work.

@mnacos jasmine-ajax is mostly useful for unit testing in which case you specifically want to avoid the call to the server.

If you're doing integration tests, this is probably not what you want and should be designed as a separate test strategy.describe("ajax calls returns", function() { var success Fn, error Fn; before Each(function () { success Fn = jasmine.create Spy("success Fn"); error Fn = jasmine.create Spy("error Fn"); j = spy On(j Query, "ajax")Call Fake( function (options) { if(/.*success.*/.test(options.url)) { options.success(); } else { options.error(); } } ); }); it("success", function () {"success/url", success Fn, error Fn); expect(success Fn)Have Been Called(); }); it("error response", function () {"error/url", success Fn, error Fn); expect(error Fn)Have Been Called(); }); }); When I specify ajax code with Jasmine, I solve the problem by spying on whatever depended-on function initiates the remote call (like, say, $or $ajax).

All and affiliated websites, operated by Ad Fair X Consultants LTD, been voluntarily content labelled with

All and affiliated websites can be blocked with free filtering tools such as the Parental Control Bar available at and by using Microsoft's Content Advisor.

Boosting is free and a great way to give back to models.Our system sorts and ranks performers based on a number we call their Power Score.A model with a higher Power Score appears higher on the home page, the model list, etc.By Boosting a model, you can help raise their Power Score and it's completely free!describe("A j Query ajax request should be able to fetch...", function() { it("an XML file from the filesystem", function() { $.ajax_get_xml_request = { has_returned : false }; // initiating the AJAX request $.ajax({ type: "GET", url: "addressbook_files/addressbookxml.xml", data Type: "xml", success: function(xml) { alert("yuppi!"); $.ajax_get_xml_request.has_returned = true; } }); // waiting for has_returned to become true (timeout: 3s) waits For(function() { $.ajax_get_xml_request.has_returned; }, "the JQuery AJAX GET to return", 3000); // TODO: other tests might check size of XML file, whether it is valid XML expect($.ajax_get_xml_request.has_returned)Equal(true); }); }); it("should make an AJAX request to the correct URL", function() { spy On($, "ajax"); get Product(123); expect($most Recent Call.args[0]["url"])Equal("/products/123"); }); function get Product(id) { $.ajax({ type: "GET", url: "/products/" + id, content Type: "application/json; charset=utf-8", data Type: "json" }); } it("should execute the callback function on success", function () { spy On($, "ajax")Call Fake(function(options) { options.success(); }); var callback = jasmine.create Spy(); get Product(123, callback); expect(callback)Have Been Called(); }); function get Product(id, callback) { $.ajax({ type: "GET", url: "/products/" + id, content Type: "application/json; charset=utf-8", data Type: "json", success: callback }); } as noted in this answer Finally, you have hinted elsewhere that you might want to write integration tests that make real AJAX requests - for integration purposes.