0
動的高さを持つ要素のclientHeightを監視し、スコープ変数をその値に設定する指示がありますが、ユニットテストの方法を決めることはできません。私が単体テストで行ったことはすべて、clientHeightは常に0を返します。私はここで同様の問題について読んだ多くの異なるソリューションを試しましたが、どれもうまくいきません。ここclientHeightを使用するディレクティブをユニットテストする
ディレクティブである:
return {
link: function (scope, element, attrs) {
scope.$watch(function() { return element[0].clientHeight; },
function(newValue, oldValue) {
if (newValue !== oldValue) {
scope.$parent.headerHeight = newValue;
}
}, true);
}
};