I am building an Ionic app and testing it using Jasmine and Karma. All my tests are passing, but when I uncomment scope.$emit I get a failure.
Directive:
angular.module('employer')
.directive('tabsIncrease', function() {
return {
restrict: 'A',
compile: function(element, attr) {
var tabular = document.querySelector('.tabs');
return function($scope, $element, $attr) {
var navigate = $element[0].querySelector('.navigate');
$scope.$on('$ionicView.beforeEnter', function() {
tabular.classList.remove('gaining');
navigate.classList.remove('no-tabular');
})
}
}
};
});
Unit Test:
beforeEach(inject(function($compile, $rootScope) {
scope = $rootScope.$new();
divElem = $('<div/>').addClass('tabular');
appending = $('body').append(divElem);
createdDirective = '<div tabs-increase></div>';
elem = angular.element(createdDirective);
compilation = $compile(elem);
compilation(scope);
scope.$digest();
}));
describe('directive', function() {
it('assign a class', function() {
scope.$digest();
expect(divElem.hasClass('gaining')).toBeFalsy();
scope.$emit('$ionicView.beforeEnter');
divElem.addClass('gaining');
expect(divElem.hasClass('gaining')).toBeTruthy();
});
});
Does anyone know why scope.$emit is not working
Aucun commentaire:
Enregistrer un commentaire