2015-10-31 38 views
1

我有以下測試:茉莉花測試角度指令:實際不是一個函數

it("should load the directive without error", function() { 
    expect($compile(inputElement)($scope)).not.toThrow(); 
}); 

和我的輸入元素包含我的指令。我的指令有一個需要在ngModel和測試的目的是爲了它來編譯沒有錯誤,如果該指令是該元素具有ngModel指令。所有這一切都在生產工作,但由於某種原因,我的測試失敗了,我得到的消息:

Actual is not a Function in __pathToJasmine/jasmine.js (line 2207) 

我還使用茉莉花2.0。現在

,我意識到實際功能$編譯,而一旦它被稱爲與$範圍是不再功能,但如何將測試我的指令是否成功編譯?

回答

2

我是皮疹做多一點修修補補之前要問的。我所做的是包的預計內容在一個匿名函數調用就像這樣:

it("should load the directive without error", function() { 
    expect(function() { 
     $compile(inputElement)($scope) 
    }).not.toThrow(); 
});