刚接触angular.js,不知道如何为具有templateUrl和隔离作用域的指令编写测试。
这是我的控制器。
这是我的views index.html &。
这是我的指示。
这是我的测试。
我正在使用Jasmine和Karma进行测试,有人能指导一下我做错了什么吗?
这是我的控制器。
(function(){
angular.module('buttons')
.controller('buttonController', ['$scope', function($scope){
//primary button
$scope.primaryButton = { name: 'Submit'};
})();
这是我的views index.html &。
<div class="layoutLeft">
<p>Primary Button</p>
<primary-button info="primaryButton"></primary-button>
</div>
primary-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);
});
});
我正在使用Jasmine和Karma进行测试,有人能指导一下我做错了什么吗?