【发布时间】:2017-03-14 15:34:54
【问题描述】:
我是 AngularJS 及其单元测试的新手。目前我正在尝试在模板文件中使用其控制器测试指令:
这是模板:
<div ng-controller = "SomeController" >
<select ng-model="data.selectedOption"
ng-options="data.code for data in data.availableOptions track by data.code">
</select>
</div>
是js文件:
angular.module('application.directives')
.directive('selector', function () {
return {
restrict: 'E',
templateUrl: 'templates.html'
};
});
现在我有一个单元测试,例如:
describe('selector', function () {
beforeEach(module('application.directives','application.templates'));
it('render the correct number of items', inject(function ($rootScope, $compile) {
var element = $compile('<selector></selector>')($rootScope);
$rootScope.$digest();
//I'd like to register the selector's controller here.
}));
});
在测试代码中,注册控制器的最佳方式是什么?我需要创建一个模拟的吗?
谢谢
【问题讨论】:
标签: angularjs unit-testing angularjs-directive controller