Новое на angular.js и не может понять, как написать тест для директивы с шаблономUrl & выделить область.Директива по угловому тестированию с шаблономUrl и область изоляции
Вот мой контроллер
(function(){
angular.module('buttons')
.controller('buttonController', ['$scope', function($scope){
//primary button
$scope.primaryButton = { name: 'Submit'};
})();
Вот мои взгляды index.html &
<div class="layoutLeft">
<p>Primary Button</p>
<primary-button info="primaryButton"></primary-button>
</div>
первичной button.html
<button class="{{buttonInfo.class}}">{{buttonInfo.name}}</button>
Вот моя директива
(function(){
angular.module('buttons')
.directive('primaryButton', function() {
return {
restrict: 'EA',
scope: {
buttonInfo: '=info'
},
templateUrl: 'scripts/local/views/primary-button.html'
}
})
})();
Вот мой тест
(function(){
beforeEach(angular.mock.module('buttons'));
describe('Buttons Directive Test', function(){
var $compile, $scope, $httpBackend;
beforeEach(module('templates'));
beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$scope = _$rootScope_.$new();
$scope.primaryButton = {name: 'Save'};
elm = angular.element("<primary-button info='buttonInfo'></primary-button>");
e = $compile(elm)($scope);
e.digest();
}));
it('should do something', function(){
expect(e.html()).toContain($scope.primaryButton);
});
});
})();
Я использую жасмин и карму для тестирования, кто-то может направлять свет на то, что я делаю неправильно
ли мое решение решить ваши проблемы? Пожалуйста, дайте мне знать. –