Angular.mock.$interval.flush()抛出奇怪的异常



我创建了以下小控制器,用于测试interval函数是否在指定的间隔

触发
angular.module('app').controller('myTstController', [
'$interval', function($interval) {
    var called = 0;
    $interval(function() {
        called++;
    }, 10);
    this.getCalled = function() { return called; }
}
]);

规范:

it('should call getSystemMessages on an interval', function() {
    var ctrl, $interval;
    angular.mock.module('app');
    angular.mock.inject(function($controller, _$interval_) {
        $interval = _$interval_;
        ctrl = $controller('myTstController', {$interval: $interval});
    });
    expect(ctrl.getCalled()).toEqual(0);
    $interval.flush(10);
    expect(ctrl.getCalled()).toEqual(1);
});

Jasmine抛出以下错误:

Error: Unexpected request: GET app/login/login.html
No more request expected
at $httpBackend (http://localhost:39474/Scripts/angular-mocks.js:1175:5)
at sendReq (http://localhost:39474/Scripts/angular.js:7817:9)
at serverRequest (http://localhost:39474/Scripts/angular.js:7551:9)
at wrappedCallback (http://localhost:39474/Scripts/angular.js:10965:15)
at Anonymous function (http://localhost:39474/Scripts/angular.js:11051:11)
at Scope.prototype.$eval (http://localhost:39474/Scripts/angular.js:11977:9)
at Scope.prototype.$digest (http://localhost:39474/Scripts/angular.js:11803:15)
at Scope.prototype.$apply (http://localhost:39474/Scripts/angular.js:12083:13)
at tick (http://localhost:39474/Scripts/angular-mocks.js:497:25)
at $interval.flush (http://localhost:39474/Scripts/angular-mocks.js:546:9)

对我来说,它看起来像我们得到一个错误,重定向应用程序到登录页面,但基于我们的代码,我无法理解为什么会发生这种情况?如果我使用flush <在最后一个expect语句中,它将失败。>

有没有人知道在这种情况下发生了什么或者我们做错了什么?

注入$httpBackend和mock

$httpBackend.expectGET('app/login/login.html').respond(200); 

解决了这个问题!

最新更新