diff --git a/js/angular/controller/slideBoxController.js b/js/angular/controller/slideBoxController.js index 98043640bb..1319fa3781 100644 --- a/js/angular/controller/slideBoxController.js +++ b/js/angular/controller/slideBoxController.js @@ -178,8 +178,6 @@ function(scope, element, $log, $document, $$q, $timeout, $interval, $$ionicAttac // adds data to the queue for selection. // Index can be either a number or a getter (to be called when starting the slide) function select(newIndex, transitionDuration, isDrag) { - newIndex = parseInt(newIndex); - if (isNaN(newIndex) || newIndex < 0) return; slideQueue.unshift([ angular.isFunction(newIndex) ? newIndex : function() { return newIndex; }, transitionDuration || SLIDE_TRANSITION_DURATION, @@ -233,8 +231,9 @@ function(scope, element, $log, $document, $$q, $timeout, $interval, $$ionicAttac } function slideTo(newIndex, duration, isDrag) { + newIndex = parseInt(newIndex); // Immediately finish invalid selection - if (!self.isValidIndex(newIndex)) return $$q.when(); + if (isNaN(newIndex) || !self.isValidIndex(newIndex)) return $$q.when(); var deferred = $$q.defer(); var delta = getDelta(selectedIndex, newIndex); diff --git a/test/unit/angular/directive/slideBox.unit.js b/test/unit/angular/directive/slideBox.unit.js index 5e077d259b..9bb16b9d89 100644 --- a/test/unit/angular/directive/slideBox.unit.js +++ b/test/unit/angular/directive/slideBox.unit.js @@ -346,11 +346,13 @@ describe('ionSlideBox', function() { // Do nothing for -1 $del.select(-1); - $timeout.verifyNoPendingTasks(); + $timeout.flush(); + expect($del.selected()).toBe(0); // Do nothing for NaN $del.select(NaN); - $timeout.verifyNoPendingTasks(); + $timeout.flush(); + expect($del.selected()).toBe(0); // parse to int $del.select('1');