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) {
        spyOn(controller, 'resetIsDirtyFlag');



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;

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