mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
test(ionicScrollController): fix PhantomJS weirdness
This commit is contained in:
@@ -52,12 +52,13 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resize = angular.bind(scrollView, scrollView.resize);
|
var resize = angular.bind(scrollView, scrollView.resize);
|
||||||
$window.addEventListener('resize', resize);
|
ionic.on('resize', resize, $window);
|
||||||
|
|
||||||
// set by rootScope listener if needed
|
// set by rootScope listener if needed
|
||||||
var backListenDone = angular.noop;
|
var backListenDone = angular.noop;
|
||||||
|
|
||||||
$scope.$on('$destroy', function() {
|
$scope.$on('$destroy', function() {
|
||||||
|
ionic.off('resize', resize, $window);
|
||||||
$window.removeEventListener('resize', resize);
|
$window.removeEventListener('resize', resize);
|
||||||
backListenDone();
|
backListenDone();
|
||||||
if (self._rememberScrollId) {
|
if (self._rememberScrollId) {
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ describe('$ionicScroll Controller', function() {
|
|||||||
|
|
||||||
beforeEach(module('ionic'));
|
beforeEach(module('ionic'));
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
ionic.Platform.ready = function(cb) { cb(); };
|
||||||
|
});
|
||||||
|
|
||||||
var scope, ctrl, timeout;
|
var scope, ctrl, timeout;
|
||||||
function setup(options) {
|
function setup(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@@ -35,21 +39,24 @@ describe('$ionicScroll Controller', function() {
|
|||||||
expect(scope.something).toBe(ctrl);
|
expect(scope.something).toBe(ctrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set bounce to !isAndroid after platformReady, if not options.boucing', function() {
|
it('should set bouncing to option if given', function() {
|
||||||
var isAndroid;
|
spyOn(ionic.Platform, 'isAndroid');
|
||||||
spyOn(ionic.Platform, 'isAndroid').andCallFake(function() {
|
|
||||||
return isAndroid;
|
|
||||||
});
|
|
||||||
setup({
|
setup({
|
||||||
bouncing: true
|
bouncing: true
|
||||||
});
|
});
|
||||||
expect(ionic.Platform.isAndroid).not.toHaveBeenCalled();
|
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();
|
setup();
|
||||||
expect(ctrl.scrollView.options.bouncing).toBe(false);
|
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();
|
setup();
|
||||||
expect(ctrl.scrollView.options.bouncing).toBe(true);
|
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) {
|
it('should unbind window event listener on scope destroy', inject(function($window) {
|
||||||
spyOn($window, 'removeEventListener');
|
spyOn(ionic, 'on');
|
||||||
spyOn($window, 'addEventListener');
|
spyOn(ionic, 'off');
|
||||||
setup();
|
setup();
|
||||||
expect($window.addEventListener).toHaveBeenCalled();
|
expect(ionic.on).toHaveBeenCalledWith('resize', jasmine.any(Function), $window);
|
||||||
expect($window.addEventListener.mostRecentCall.args[0]).toBe('resize');
|
|
||||||
scope.$destroy();
|
scope.$destroy();
|
||||||
expect($window.removeEventListener).toHaveBeenCalled();
|
expect(ionic.off).toHaveBeenCalledWith('resize', jasmine.any(Function), $window);
|
||||||
expect($window.removeEventListener.mostRecentCall.args[0]).toBe('resize');
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('rememberScrollPosition should set id', function() {
|
it('rememberScrollPosition should set id', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user