0
我是爲angularJS工廠編寫jasmine測試用例的新手。 我想測試整個工廠,但我無法取得getKeys
。這是我的工廠。angularjs工廠的Jasmine 2.0單元測試
我廠是:
'use strict';
var a11yModule = angular.module('TestModule', ['ui.bootstrap']);
a11yModule.factory('TestFacotry', ['$q', '$timeout', function ($q, $timeout) {
return {
getKeys: function() {
return {
"abc": 32,
"gpa": 33,
"end": 35
};
}
};
}])
我的單位規格是:
describe('modu testing', function() {
var TestFacotryMock, q, timeout;
beforeEach(module('TestModule', ['ui.bootstrap']));
beforeEach(inject(function (_$q_, _$timeout_, _TestFacotry_) {
q = _$q_;
timeout = _$timeout_;
TestFacotryMock = _TestFacotry_;
}));
it('Should ', function() {
//var output = TestFacotryMock.getKeys.something();
expect(typeof getKeys()).toBe('function');
});
});
誤差
錯誤:[$注射器:modulerr]無法實例模塊TestModule由於: 錯誤:[$ injector:modulerr]無法實例化模塊ui.bootstrap,原因如下: 錯誤:[$ injector:nomod]模塊'ui.bootstrap'不可用!您拼錯了模塊名稱或忘記加載模塊名稱。如果註冊模塊確保您指定依賴關係作爲第二個參數。
你並不需要通過'[ 'ui.bootstrap']'測試時,只是'beforeEach(模塊( 'TestModule'));'應該做 – tanmay
即使沒有通過'ui.bootstrap'也得到相同的錯誤 – lucky
請在您的karma-conf.js文件中添加ui-bootstrap作爲文件:[ 'bower_components/*/*/ui-bootstrap.js'] – ramanathan