Внутри directive
шахты наречено data-type-ahead
я следующий в серии событий:AngularJS Test Unit element.bind
$scope.test = 5;
// Bind blur event and clear the value of
element.bind('blur', function(){
$scope.test = 0;
});
Я попытался множество вещей, чтобы использовать в модульном тесте, чтобы правильно проверьте функциональность этого события blur
, однако я не был успешным. Я видел упоминание функции triggerHandler
. Вот моя попытка модульного тестирования:
//Inject $compile and $rootScope before each test.
beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$scope.test = 5
html = angular.element('<input type="text" data-type-ahead/>');
//Apply $scope to directive html.
directive = $compile(html)($scope);
//Trigger digest cycle.
$scope.$digest();
}));
it('should trigger the events bound to the blur event on the directive', function() {
html.triggerHandler('blur')
expect($scope.test).toEqual(0);
});
Однако это не удается, потому что $scope.test
пребывает на 5. Является ли это HTML-элемент является неправильным, мне нужен другой $digest
или $apply
для после того, как я вызвать событие?