Angularjs 因果报应在角度超时内不调用私有函数

Angularjs 因果报应在角度超时内不调用私有函数,angularjs,unit-testing,timeout,jasmine,karma-jasmine,Angularjs,Unit Testing,Timeout,Jasmine,Karma Jasmine,我有一个控制器,它在超时几秒钟后调用私有函数。控制器工作正常。当我试图使用karma with jasmine框架编写单元测试用例时,它并没有在超时内调用我的私有函数 我使用了timeout.flush(),它在超时内,但没有调用私有函数。下面是我的控制器代码 var counter = 0; foo(1000); function foo(timeout){ $http({ method: 'GET', timeout : timeout,

我有一个控制器,它在超时几秒钟后调用私有函数。控制器工作正常。当我试图使用karma with jasmine框架编写单元测试用例时,它并没有在超时内调用我的私有函数

我使用了timeout.flush(),它在超时内,但没有调用私有函数。下面是我的控制器代码

var counter = 0;
foo(1000);
function foo(timeout){
     $http({
          method: 'GET',
          timeout : timeout,
          url : "URL to get data"
     }).success(function(res){

     }).error(function(err){
          callinterval(0);
     });
}

function callinterval(code){
     if(counter < 3){
        $timeout(function(){
            foo(5000);
            counter++;
        }, 5000);
     }else{
        $("#errorModal").modal(modalOption);
     }
}
若我使控制器中的计数器等于3,那个么我就能够通过这个测试。i、 例如,如果计数器等于3,karma能够在超时时通过该函数。若计数器小于3,则不调用函数foo

it('Test backend connection 505 failure', function() {
    console.log("Test backend connection 505 failure");
    var controller = createController();
    var errorMessage='';

    try {
        // set the HTML response status to 500, service failure
        httpBackend.when('GET','URL to get data')
            .respond(500);

        httpBackend.flush();
        timeout.flush();
    } catch(err) {
        errorMessage = err.message
        console.log(errorMessage);
    }

    expect(errorMessage).toMatch("errorModal");
});