Here’s an example of how to fake out an ajax call, and then test that some methods get called in jasmine.

    it ("should reset the isDirty flag after doing a save", function() {

        spyOn($, "ajax").andCallFake(function(params) {
              params.success('1');
        });
        spyOn(controller, 'resetIsDirtyFlag');

        controller.saveDraft();

        expect(controller.resetIsDirtyFlag).toHaveBeenCalled();
    });

The spyon($, “ajax”).andCallFake takes a fake function and returns it (along with whatever data you pass it) as the response to your ajax call. In this case I am simulating a successful call to the backend, and returning an id.

Then when you call your object under test (controller.saveDraft()) you can assert that certain things happen.

In this case I want to verify that the resetIsDirtyFlag method got called.

DraftController.prototype.saveDraft = function () {

    that = this;

    $.ajax({
        url: that.saveUrl(),
        type: 'POST',
        data: $("#InvoiceForm").serialize(),
        success: function (data) {
            that.resetIsDirtyFlag();
        },
        error: function (data) {
            that.showError();
        }
    });
};