vendredi 6 mai 2016

Unit testing a directive that uses clientHeight

I have a directive that watches the clientHeight of an element with dynamic height and sets a scope variable to that value, but I can't figure out how to unit test it at all. Everything I've done in the unit tests, clientHeight always returns 0. I've tried a number of different solutions I've read for similar problems on here, but none of them work.

Here is the directive:

return {
  link: function (scope, element, attrs) {
    scope.$watch(function () { return element[0].clientHeight; },
      function(newValue, oldValue) {
        if (newValue !== oldValue) {
          scope.$parent.headerHeight = newValue;
        }
      }, true);
  }
};

Aucun commentaire:

Enregistrer un commentaire