Angular Jasmine测试没有找到模块

xen*_*ide 3 javascript jasmine angularjs

所以我的测试是抱怨它无法找到 ui.bootstrap

INFO [karma]: Karma v0.10.2 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
WARN [watcher]: Pattern "/home/xenoterracide/lm/frontend/test/mock/**/*.js" does not match any file.
INFO [Chrome 30.0.1599 (Linux)]: Connected on socket 15lSt3HPpk9b-rKPvQzY
Chrome 30.0.1599 (Linux) Controller: Week should attach days of the week to scope FAILED
    Error: No module: ui.bootstrap
        at Error (<anonymous>)
        at /home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:1211:17
        at ensure (/home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:1152:38)
        at module (/home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:1209:14)
        at /home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:2904:24
        at Array.forEach (native)
        at forEach (/home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:130:11)
        at loadModules (/home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:2900:5)
        at /home/xenoterracide/lm/frontend/app/bower_components/angular/angular.js:2905:38
        at Array.forEach (native)
    TypeError: Cannot read property 'days_of_the_week' of undefined
        at null.<anonymous> (/home/xenoterracide/lm/frontend/test/spec/controllers/week.js:20:17)
Chrome 30.0.1599 (Linux): Executed 1 of 1 (1 FAILED) ERROR (0.126 secs / 0.017 secs)
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

Elapsed time
concurrent:test  1s
Run Code Online (Sandbox Code Playgroud)

这是我的app.js,这是我加载的地方ui.bootstrap.

'use strict';

angular.module('lmApp', [
    'ui.bootstrap',
    'ui.router'
])
.config(['$stateProvider', '$urlRouterProvider',
    function ( $stateProvider, $urlRouterProvider ) {
            $urlRouterProvider.otherwise('/')
            $stateProvider.state('index', {
                    url: "", // root
                    views: {
                            "Nav":        { templateUrl: "views/nav.html" },
                            "Week":       { templateUrl: "views/week.html" },
                    },
            })
    }
])
.factory('now', function () { return new Date })
;
Run Code Online (Sandbox Code Playgroud)

这是我的考试

'use strict';

describe('Controller: Week', function () {

  // load the controller's module
  beforeEach(module('lmApp'));

  var MainCtrl,
    scope;

  // Initialize the controller and a mock scope
  beforeEach(inject(function ($controller, $rootScope) {
    scope = $rootScope.$new();
    MainCtrl = $controller('Week', {
      $scope: scope
    });
  }));

  it('should attach days of the week to scope', function () {
    expect(scope.days_of_the_week.length).toBe(7);
  });
});
Run Code Online (Sandbox Code Playgroud)

ten*_*ent 9

问题在错误日志中说明时说:

Error: No module: ui.bootstrap
Run Code Online (Sandbox Code Playgroud)

基于此,我猜你在Karma配置文件(通常称为karma.conf.js)中错过了一步.您需要在配置中提供应用程序所需的所有必需库,以便Karma知道在运行测试之前将这些库加载到内存中.当你调用时beforeEach(module('lmApp'));,Karma会尝试创建你的lmApp模块,但不能因为它的一个(或多个)声明的依赖项不可用.

我99%肯定如果你只是ui.bootstrapfiles: {}你的业力配置部分包含源代码,它应该开始工作.

有关详细信息,请参阅此处的业力文档.