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);
}
};