jeudi 9 avril 2015

AngularJS - Unit test with $window object

I have a directive that look like this:



angular.directive('myDirective', ['$window', function(,$window){
return {
link: function(scope, element, attr, controller) {
var w = angular.element($window);
function showscroll(){
var scrollTop = w.scrollTop();
console.log("scrollTop:"+scrollTop);
// some more code that works with $window scrollTop
}
function showsize(){
var height = w.height();
var width = w.width();
console.log("window size:"+width+"x"+height);
// some more codes that works with $window size
}
w.bind('scroll', function () {
showscroll();
});
w.bind('resize', function () {
showsize();
});
showscroll();
showsize();

}
};
}]);


How can I mock $window object and do unit test to ensure showscroll() and showsize() working as expected?


Aucun commentaire:

Enregistrer un commentaire