1
Написал простую директиву с событием click. Это выглядит так:elem.click не происходит в угловом модульном тесте?
var app = angular.module('plunker', []);
app.directive('myDirective',
function() {
return {
restrict: 'E',
template: '<span ng-click="klik();">{{value}}</span>',
controller:function($scope)
{
$scope.klik= function()
{
$scope.value='you clicked on it!!';
}
}
}
}
);
Я не могу вызвать событие щелчка, почему? Это тестовый модуль:
describe('testing directive', function(){
var scope, html, elem, compiled;
beforeEach(function(){
module('plunker');
html = '<my-directive></my-directive>';
inject(function($compile, $rootScope) {
//create the scope.
scope = $rootScope.$new();
//get the element.
elem = angular.element(html);
//compile the view.
compiled = $compile(elem);
//run the view against the scope.
compiled(scope);
//call digest to update the view!
scope.$digest();
});
});
it('should set text to "you clicked on it!"', function(){
elem.click();
expect(elem.value).toBe('you clicked on this!');
});
})
Это ошибка:
TypeError: elem.click is not a function
plunkr исх: http://plnkr.co/edit/e4Iood6Xm1qltOtIjo3Z?p=preview
отличная, но ссылка plunkr, которую вы отправили, является старой? – Pindakaas
Упс. Попробуйте следующее: http://plnkr.co/edit/OZnkbaP34p0IJBLRKLbe?p=streamer Также исправлен ответ. –