在服务方法的单元测试中没有发生调用假

Call fake not happening in unit testing of service method

  function logOutUser() {
            var url = "User/Logout";
            httpWrapperService.post(url, {}, {}).then(function (success) {

            },
            function error(error) {

            });
            localStorageService.clearLocalStorage();
            httpWrapperService.setAuthenticationToken(null);
        }

这里是测试代码

'use strict';

describe('Testing registration-service\n\n', function () {

var httpBackend = null;

var baseURL = null;
var services = {
    registration: null,
    settings: null,
    httpservice:null
};

// Initialization before tests
 beforeEach(function () {
        module("app");

        // Inject needed services
        inject(function ($httpBackend, _registrationService_, _settingsService_, _httpWrapperService_) {
            services.registration = _registrationService_;
            services.settings = _settingsService_;
            httpBackend = $httpBackend;
            httpservice=_httpWrapperService_;
            //modal=$modal
            // Get baseurl
            baseURL = services.settings.getServicesURL();

            // Default answer
            httpBackend.whenGET("languages/en.json").respond("OK");
        });
    });

  describe('Checking logOutUser() function for different test cases!!!\n', function () {

    jasmine.createSpy('setAuthenticationToken').and.CallFake(function() {
      //a fake implementation
    });

    console.log("setAuthenticationToken===", setAuthenticationToken);

        it("1. When user is logged in \n", function (done) {
           localStorage.SA_User='{"tokenId":"TICKET_1","rememberMe":true}';
           var url = baseURL + "User/Logout";
           httpBackend.whenPOST(url, {}).respond({});
           expect(localStorage.SA_User).toEqual(undefined);
           ///expect(1).toEqual(1);
           done();
        });

    });

});

我在注册服务 (logoutuser) 中定义了一个函数。我想对这个函数进行单元测试。我不想调用 httpWrapperService.setAuthentication 函数。 我该怎么做,我尝试使用 jasmine 和 spy 使用 callfake 但无法在业力中做到这一点。

感谢任何帮助!!!! 谢谢

尝试:spyOn(services.httpservice, 'setAuthenticationToken').and.callFake(function(){}) 而不是 jasmine.createSpy。这应该将间谍添加到服务中。