我試圖單元測試控制器代碼,需要其他模塊依賴一個模塊內,但一直沒能弄清楚如何正確地嘲笑他們。嘲諷角模塊依賴測試
我使用的茉莉花框架,並與噶(Testacular)上運行我的測試。
模塊代碼
var app = angular.module('events', ['af.widgets', 'angular-table']);
app.controller('eventsCtrl', function([dependencies]){
$scope.events = [];
...
});
規格代碼
describe('events module', function(){
var $scope,
ctrl;
beforeEach(function(){
angular.mock.module('af.widgets', []);
angular.mock.module('angular-table', []);
module('events', ['af.widgets', 'angular-table']);
});
beforeEach(inject(function($rootScope, $controller){
$scope = $rootScope.new();
ctrl = $controller('NameCtrl', {
$scope: $scope,
});
}));
it('should have an empty events array', function(){
expect($scope.events).toBe([]);
})
});
我得到的錯誤是噶是 「沒有模塊af.widgets」,所以很明顯,我不是嘲笑模塊依賴關係。任何提示?
$範圍= $ rootScope.new();應該是$ scope = $ rootScope。$ new();(可能是我們的版本) –