자스민의 각도 지시 측정 방법에 대한 쓰기 테스트가 필요합니다. toHaveBeen을 테스트하는 방법은 다음 코드에서 .css 메서드를 호출 했습니까? 이 방법으로 스파이를 만들려고했지만 항상 Expected spy css to have been called.
이 있습니다. css 메소드 호출을 테스트하는 것이 좋은 생각입니까? 테스트에각도 측정 지시어 - angular.element.css
지침 방법 :
scope.contentPadding =() => {
const bars = angular.element(element[0].querySelectorAll('.intro'));
if (bars.length > 0) {
const bar = angular.element(bars[bars.length - 1]);
bar.parent().css('padding-top', `${bar[0].offsetHeight - 10}px`);
}
};
내 테스트 구현 :
describe('test', function() {
var $rootScope,
$compile,
$scope,
$window,
element;
function compileDirective() {
var html = angular.element(`
<div my-directive-name>
<div class="section">
<div class="intro"></div>
</div>
</div>`);
element = $compile(html)($scope);
$scope.$digest();
}
beforeEach(function() {
angular.mock.module('my-directive-name');
inject(function(_$rootScope_, _$compile_, _$window_) {
$rootScope = _$rootScope_;
$compile = _$compile_;
$window = _$window_;
$scope = $rootScope.$new();
compileDirective();
});
});
describe('padding', function() {
it('adds top padding', function() {
var el = angular.element(element[0].querySelector('.section'));
spyOn(el, 'css');
$scope.contentPadding();
$scope.$digest();
expect(el.css).toHaveBeenCalled();
});
});
});
이 우리에게 현재 테스트를 표시합니다. –