diff --git a/js/ext/angular/src/controller/ionicScrollController.js b/js/ext/angular/src/controller/ionicScrollController.js index ac3d74d99e..f34a9d01b0 100644 --- a/js/ext/angular/src/controller/ionicScrollController.js +++ b/js/ext/angular/src/controller/ionicScrollController.js @@ -52,12 +52,13 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca } var resize = angular.bind(scrollView, scrollView.resize); - $window.addEventListener('resize', resize); + ionic.on('resize', resize, $window); // set by rootScope listener if needed var backListenDone = angular.noop; $scope.$on('$destroy', function() { + ionic.off('resize', resize, $window); $window.removeEventListener('resize', resize); backListenDone(); if (self._rememberScrollId) { diff --git a/js/ext/angular/test/controller/ionicScrollController.unit.js b/js/ext/angular/test/controller/ionicScrollController.unit.js index f9e73884fc..9f57e95cd8 100644 --- a/js/ext/angular/test/controller/ionicScrollController.unit.js +++ b/js/ext/angular/test/controller/ionicScrollController.unit.js @@ -2,6 +2,10 @@ describe('$ionicScroll Controller', function() { beforeEach(module('ionic')); + beforeEach(function() { + ionic.Platform.ready = function(cb) { cb(); }; + }); + var scope, ctrl, timeout; function setup(options) { options = options || {}; @@ -35,21 +39,24 @@ describe('$ionicScroll Controller', function() { expect(scope.something).toBe(ctrl); }); - it('should set bounce to !isAndroid after platformReady, if not options.boucing', function() { - var isAndroid; - spyOn(ionic.Platform, 'isAndroid').andCallFake(function() { - return isAndroid; - }); + it('should set bouncing to option if given', function() { + spyOn(ionic.Platform, 'isAndroid'); setup({ bouncing: true }); expect(ionic.Platform.isAndroid).not.toHaveBeenCalled(); - - isAndroid = true; + }); + it('should set bouncing false if isAndroid true', function() { + spyOn(ionic.Platform, 'isAndroid').andCallFake(function() { + return true; + }); setup(); expect(ctrl.scrollView.options.bouncing).toBe(false); - - isAndroid = false; + }); + it('should set bouncing true if android false', function() { + spyOn(ionic.Platform, 'isAndroid').andCallFake(function() { + return false; + }); setup(); expect(ctrl.scrollView.options.bouncing).toBe(true); }); @@ -139,14 +146,12 @@ describe('$ionicScroll Controller', function() { }); it('should unbind window event listener on scope destroy', inject(function($window) { - spyOn($window, 'removeEventListener'); - spyOn($window, 'addEventListener'); + spyOn(ionic, 'on'); + spyOn(ionic, 'off'); setup(); - expect($window.addEventListener).toHaveBeenCalled(); - expect($window.addEventListener.mostRecentCall.args[0]).toBe('resize'); + expect(ionic.on).toHaveBeenCalledWith('resize', jasmine.any(Function), $window); scope.$destroy(); - expect($window.removeEventListener).toHaveBeenCalled(); - expect($window.removeEventListener.mostRecentCall.args[0]).toBe('resize'); + expect(ionic.off).toHaveBeenCalledWith('resize', jasmine.any(Function), $window); })); it('rememberScrollPosition should set id', function() {