2013-10-16 80 views
3

所以我的測試是抱怨無法找到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 

這裏是我的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 }) 
; 

這裏是我的測試

'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); 
    }); 
}); 

回答

9

問題是在錯誤日誌中稱,當它說:

Error: No module: ui.bootstrap 

此基礎上,我會想你是失蹤Karma配置文件中的一個步驟(通常稱爲karma.conf.js)。您需要在您的配置中提供應用程序所需的所有必需庫,以便Karma知道在運行測試之前將這些庫加載到內存中。當您致電beforeEach(module('lmApp'));時,Karma會嘗試創建您的lmApp模塊,但不能因爲其聲明的一個(或多個)依賴關係不可用。

我99%確定如果你只在你的karma配置的files: {}部分包含ui.bootstrap的源代碼,它應該開始工作。

查看karma文檔here瞭解更多信息。

+0

是的,將文件添加到conf修復了錯誤。 – xenoterracide

+0

對我來說,我是用jasmine/rspec將文件添加到'spec/javascripts/spec_helper.coffee' –