2013-08-22 82 views
3

我嘗試使用Chutzpah + jasmine來測試我的AngularJS代碼。Chutzpah + AngularJS + jasmine的測試指令

這裏有文件,我引用

jasmine.js ver:1.3.1

jasmine-html.js

angular.min.js ver:1.2.0RC1

angular-mocks.js

alert.js

,如果我不測試與模板任何它的實際工作。

我覺得在加載模板時一定有什麼問題。

以下是我在嘗試從AngularJS UI Bootstrap運行警報指令時的做法。

我不在下面的測試中使用這種方式,因爲它是用於Karma跑步者。

beforeEach(module('template/alert/alert.html'));

我用了不同的方法,從這個post

beforeEach(inject(function ($templateCache) { 
     var directiveTemplate = null; 
     var req = new XMLHttpRequest(); 
     req.onload = function() { 
      directiveTemplate = this.responseText; 
     }; 
     req.open("get", "../../../template/alert/alert.html", false); 
     req.send(); 
     $templateCache.put("template/alert/alert.html", directiveTemplate); 
    })); 

它仍然有很多的問題,但我認爲模板被加載。

只有「不應該顯示關閉按鈕,如果沒有指定接近回調」通過

大多數錯誤都喜歡

類型錯誤:「未定義」不是(評估「預計(alerts.eq功能(0 ))。toHaveClass('alert-success')')in ...

看起來好像沒有創建警報。

由於第一個錯誤是

Test 'alert:should generate alerts using ng-repeat' failed Expected 0 to equal 3.

任何想法?

+0

我收到錯誤:**未能在'XMLHttpRequest'上執行'發送':未能加載** –

回答

3

最後,我想通了。

我需要引用2個文件。

jQuery和Jasmine-jQuery

+1

您好,先生,是真正的英雄! – Voles

相關問題