[英]When unit-testing my angularJS application with Jasmine, $interval is undefined
When writing unit tests for my application using Jasmine I have a $interval function which i need to test. 使用Jasmine为我的应用程序编写单元测试时,我有一个需要测试的$ interval函数。 To that extend, I am trying to inject $interval and call $interval.flush();
为此,我试图注入$ interval并调用$ interval.flush();。
I have the following code (this is a stripped version) 我有以下代码(这是剥离的版本)
describe("whatever", function () {
var $interval;
beforeEach(function () {
angular.mock.module('whatever');
angular.mock.inject(function (_$interval_) {
$interval = _$interval_;
});
});
describe("requestIntervalFunction", function () {
$interval.flush(21000); //this gives me error "Cannot read property "flush" of undefined
});
My question is, how come that it says $interval is undefined? 我的问题是,为什么说$ interval是未定义的?
You are missing your specificaton
part.Thats why you getting such an error. 您缺少
specificaton
部分,这就是为什么您会收到这样的错误。
Add by define it
function 通过定义
it
添加功能
describe("requestIntervalFunction", function() {
it("test",function(){
$interval.flush(21000); //this gives me error "Cannot read property "flush" of undefined
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.