//тесты для текущего(твоего) варианта директивы describe('statsHeight', function() { var $compile, $rootScope, $timeout; beforeEach(function () { angular.mock.module('gby.common'); }); beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_){ $compile = _$compile_; $rootScope = _$rootScope_; $timeout = _$timeout_; })); it('string length less than 4', function() { var element, fontSize = 93, content = '999'; element = $compile('
')($rootScope); $rootScope.$digest(); $timeout.flush(); expect(element.html().length).toBeLessThan(4); expect(element.css('font-size')).toEqual(fontSize+'px'); }); it('string length greater than 3', function() { var element, fontSize = 93, content = '999569'; element = $compile('
')($rootScope); $rootScope.$digest(); $timeout.flush(); expect(element.html().length).toBeGreaterThan(3); expect(element.css('font-size')).toEqual((fontSize-10*(content.length-1))+'px'); }); }); //мой вариант директивы(без отслеживания baseMetrics), тесты commonModule.directive('statsHeight', function ($timeout) { return { restrict: 'A', link: function (scope, element, attrs) { var collection={}; scope.$watchCollection( function() { collection.length = element.text().length; collection.fontSize = parseFloat(attrs.statsHeight); return collection; }, function (newCollection) { var newFontSize = newCollection.length < 4 ? newCollection.fontSize : newCollection.fontSize - 10 * (newCollection.length - 1); element.css({ "font-size" : newFontSize }); }); } } }); //тесты describe('statsHeight', function() { var $compile, $rootScope, $timeout; beforeEach(function () { angular.mock.module('gby.common'); }); beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_){ $compile = _$compile_; $rootScope = _$rootScope_; $timeout = _$timeout_; })); it('string length less than 4', function() { var element, fontSize = 93, content = '999'; element = $compile('
')($rootScope); $rootScope.$digest(); expect(element.text().length).toBeLessThan(4); expect(element.css('font-size')).toEqual(fontSize+'px'); }); it('string length greater than 3', function() { var element, fontSize = 93, content = '999569'; element = $compile('
')($rootScope); $rootScope.$digest(); expect(element.text().length).toBeGreaterThan(4); console.log((fontSize-10*(content.length-1))); expect(element.css('font-size')).toEqual((fontSize-10*(content.length-1))+'px'); }); });