0
當我試圖讓我的AngularJS應用中的一些單元測試。我已經制作了幾個測試套件,所有這些套件都能正常工作。然而,測試一定controller
時,我得到了以下錯誤:AngularJS - 獲得「論證‘FN’不是一個函數,得到了字符串」測試特定的控制器
Error: [ng:areq] Argument 'fn' is not a function, got string
看來它的起源是在注入的依賴關係。這裏的beforeEach
代碼:
beforeEach(function() {
angular.mock.module('mapInteractions');
inject(function(_$controller_, _$rootScope_, _$q_) {
$controller = _$controller_;
$rootScope = _$rootScope_;
$q = _$q_;
}); //<-------- IT BLAMES THIS EXPRESSION
inject(function(_userProgressService_,
_mapMarkersService_,
_PointAPlaceController_) {
//custom services and controllers
userProgressService = _userProgressService_;
mapMarkersService = _mapMarkersService_;
PointAPlaceController = _PointAPlaceController_;
}); //if I remove the previous inject, it blames this one
//...
}
我是第一次使用
BardJS's inject method
,因爲它與所有其他套件的工作,但後來我想,如你所見,原來的功能和錯誤依然存在。
這是很奇怪,因爲我在測試方式完全相同另一個控制器,但一切正常吧。
可以檢測出問題了嗎?
對不起,我不明白......難道說,我應該在我的控制器/服務代碼或我的控制器/服務測試代碼檢查?因爲對於測試,我只需要使用本地服務調用'inject',比如'$ controller',並且失敗。 我想我理解你的擔憂,儘管......我更深入地研究了錯誤,轉到[它的頁面](http://errors.angularjs.org/1.3.20/ng/areq?p0= fn&p1 = not%20a%20function%2C%20got%20string),看起來有什麼地方沒有定義... – pavlag
我認爲這個錯誤是在你的'mapInteractions'模塊中定義的一個服務。 –
你是對的!定義一些路由時,我錯誤地聲明瞭一些'module.run()'表達式。每次模塊運行時,都會引發異常。恥辱,它不是更詳細。 – pavlag