2016-11-26 34 views
0

所以我有需要有測試覆蓋現有的組項目。該項目使用npm和angularJS。我開始做一個NPM安裝jQuery的,還有茉莉,和角嘲笑。我認爲一個好的,簡單的地方開始(沒有太多的測試經驗)將與路由。我這裏定義在現有AngularJS /引導項目沒有模塊發現使用茉莉花

app.config(['$routeProvider', function ($routeProvider) { 
    $routeProvider 
    .when("/", 
     { templateUrl: "partials/home/home.html", 
      controller: "PageCtrl" 
     }) 
    // else 404 
    .otherwise("/404", 
     { templateUrl: "partials/404.html", 
      controller: "PageCtrl" 
     }); 
}]); 

一些非常基本的路由和我開始寫測試。始於一個非常簡單的例子在線獲得

describe('Route testing', function() { 

    beforeEach(module('tutorialWebApp')); 


    it('should route accordingly', inject(function ($route) { 
    expect($route.routes['/'].controller).toBe('PageCtrl'); 
    expect($route.routes['/'].templateUrl).toEqual('partials/home/home.html'); 
    })); 
}); 

我得到一個類型錯誤:模塊是不是一個函數,指着我beforeEach線。我研究了這個問題,並且我發現的解決方案都沒有取得任何進展。任何幫助,將不勝感激

回答

0

beforeEach接受一個回調函數。你的代碼調用模塊功能,這顯然不返回的功能。您對模塊的調用必須封裝在回調函數中。像這樣:

beforeEach(function(){ 
    module('tutorialWebApp'); 

    // some other code 
}); 
+0

仍然說模塊不是一個功能。 –

+0

沒有。 [單元測試角引導](https://docs.angularjs.org/guide/unit-testing)建議OP的貼有問題的方式是正確的。 – tanmay