我创建了以下小控制器,用于测试间隔函数是否在指定间隔触发
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);
});
茉莉花抛出以下错误:
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 < 10,它将在最后一个期望语句中按预期失败。
有谁知道在这种情况下发生了什么或我们做错了什么?