由于ngIdle模块,Karma / Jasmine测试用例失败

时间:2014-07-30 18:49:08

标签: unit-testing karma-jasmine ng-idle

  

错误:[$ injector:modulerr]由于以下原因导致无法实例化模块ngIdle:   错误:[$ injector:nomod]模块'ngIdle'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

我错过了什么?如果我不包含ngIdle模块并删除它的实现代码,那么我的所有业力/茉莉花测试都会通过但是包含了ngIdle,我的所有100多个测试用例都失败并且出现上述错误。我按此顺序在ngIdle中添加了karma.conf.js

files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-touch/angular-touch.js',
'app/bower_components/angular-animate/angular-animate.js',
'app/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/revolunet-angular-carousel/lib/angular-mobile.js',
'app/bower_components/revolunet-angular-carousel/src/angular-carousel.js',
'app/bower_components/jquery/dist/jquery.js',
'app/bower_components/angular-cookies/angular-cookies.min.js',
'app/bower_components/ng-idle/angular-idle.min.js',
'app/bower_components/ng-grid/ng-grid-2.0.11.min.js',
'app/js//*.js',
'test/spec//*.js'
 ],

下面是我的bower.json,这样你就可以了解我正在使用的版本

{
  "name": "combo",
  "version": "0.5.1",
  "dependencies": {
    "angular": "~1.3",
    "angular-route": "~1.3",
    "angular-touch": "~1.3",
    "angular-animate": "~1.3",
    "angular-resource": "~1.3",
    "angular-cookies": "~1.3",
    "angular-bootstrap": "~0.11.0",
    "revolunet-angular-carousel": "~0.2.2",
    "ng-grid": "~2.0.7",
    "ng-idle": "latest",
    "video.js": "~4",
    "highcharts": "~3.0.7",
    "jquery": "~2",
    "jquery-ui": "~1.10.4",
    "jqueryui-touch-punch": "git://github.com/furf/jquery-ui-touch-punch.git",
    "angular-snap": "~1.4.1",
    "snapjs": "latest"
  },
  "devDependencies": {
    "angular-mocks": "~1.3",
    "angular-scenario": "~1.3"
  },
  "resolutions": {
    "angular": "~1.2.10",
    "angular-touch": "~1.2.10",
    "jquery": "^1.8.0"
  }
}

1 个答案:

答案 0 :(得分:1)

您必须将 angular-idle.min.js 添加到 karma.conf.js

files: [
  //Configs
  'config.js',

  'lib/angular/angular.min.js',
  'lib/angular-mocks/angular-mocks.js',
  'lib/moment/moment.js',
  'lib/ng-idle/angular-idle.min.js',
  'lib/angular-moment/angular-moment.js',
  // ... another libraries
],