Como testar uma função que chama uma função AJAX sem dispará-la usando jasmim?

Eu fiz o check-inComo verifico os eventos do jQuery AJAX com o Jasmine? eComo testar um controlador Angular com uma função que faz uma chamada AJAX sem zombar da chamada AJAX? mas, por alguma razão, eles não necessariamente apresentam um formato que funcione para mim.

Meu problema é que estou testando uma função que faz uma chamada para uma função que dispara uma solicitação AJAX. Quero testar a função externa sem disparar a solicitação AJAX (ou interromper essa solicitação) para não receber um monte de dados defeituosos no servidor de dados.

Aqui está minha função externa (que chama a função que contém o AJAX):

vm.clickSubmit = function () {
    vm.loading = true; // starts the loading spinner
    vm.updateData(); // makes current data current in the data model
    vm.inputData = {    // build the data to be submitted
        ...
    };
    vm.submit(); // calls the AJAX function
};

Aqui está minha função AJAX:

vm.submit = function () {
    var d = $.ajax({
        type: "POST"
        , data: angular.toJson(vm.inputData)
        , url: "http://submit_the_data"
        , contentType: "application/json"
        , xhrFields: { withCredentials: true }
        , crossDomain: true
    })
    .success(function (resp) {
        DataService.ticketNumber = resp; // returns ticket# for the data model
    })
    .error(function (error) {
        DataService.ticketNumber = DataService.submitError;
    });
    d.then(function (d) {
        vm.loading = false; // stops the loading spinner
        DataService.tickets = []; // empty's the array to be filled anew
        $location.path('/submitted'); // success splash html
        $scope.$apply();
    });
};

Eu escrevi todos os testes que lerão e verificarão os valores noinputData objeto, mas não tenho certeza de como cercar a chamada paraclickSubmit() portanto, nada é realmente enviado ao servidor. Eu cheguei a este ponto no meu teste de unidade:

'use strict';

describe('Controller: HomeController', function () {
    beforeEach(module('tickets'));
    var controller, scope, $location, DataService;
    var tests = 0;
    beforeEach(inject(function ($rootScope, $controller, _$location_, _DataService_) {
        $location = _$location_;
        DataService = _DataService_;
        scope = $rootScope.$new();
        controller = $controller('HomeController', {
            $scope: scope
        });
    }));
    afterEach(function () {
        tests += 1;
    });
    describe('clickSubmit should verify data and submit new ticket', function () {
        beforeEach(function () {
            jasmine.Ajax.install();
            controller.loading = false;
                ... // inputData fields filled in with test data
        });
        afterEach(function () {
            jasmine.Ajax.uninstall();
        });
        it('should start the spinner when called', function () {
            controller.clickSubmit();
            expect(controller.loading).toBeTruthy();
        });
        // other it('') tests
    });
    it('should have tests', function () {
        expect(tests).toBeGreaterThan(0);
    });
});

Então, o que deve acontecer após a espera no botão giratório de carregamento para cancelar a chamada paravm.submit() no código real?

Obrigado,

-C§

questionAnswers(1)

yourAnswerToTheQuestion