我试图在一个模块中对控制器代码进行单元测试,该模块将其他模块作为依赖项,但是无法弄清楚如何正确地模拟它们.
我正在使用Jasmine Framework并使用Karma(Testacular)运行我的测试.
模块代码
var app = angular.module('events', ['af.widgets', 'angular-table']);
app.controller('eventsCtrl', function([dependencies]){
$scope.events = [];
...
});
Run Code Online (Sandbox Code Playgroud)
规格代码
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([]);
})
});
Run Code Online (Sandbox Code Playgroud)
我得到的错误是Karma是"没有模块af.widgets",所以显然我并没有正确地模仿模块依赖.任何提示?