From 03bf67d42f987699a51c5837fbb580e7e1d3aa8f Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Tue, 11 Feb 2014 11:49:37 -0500 Subject: [PATCH] test(ionicContent): mock scrollView.{scrollTo,getValues} --- .../angular/test/directive/ionicContent.unit.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/js/ext/angular/test/directive/ionicContent.unit.js b/js/ext/angular/test/directive/ionicContent.unit.js index abca653bf1..6de09dd1eb 100644 --- a/js/ext/angular/test/directive/ionicContent.unit.js +++ b/js/ext/angular/test/directive/ionicContent.unit.js @@ -82,14 +82,26 @@ describe('Ionic Content directive', function() { var parent = angular.element('
'); //Make a phony element that tells the world it's a navView when in reality it's just a div parent.data('$navViewController', true); - parent.append(''); + parent.append('
hello

'); compile(parent)(scope); scope.$apply(); + + /* Mock setting and getting scroll because we don't have time for the dom to load */ + var scrollValues = {}; + spyOn(scope.scrollView, 'scrollTo').andCallFake(function(left, top, a, zoom) { + scrollValues = { + left: left || 0, + top: top || 0, + zoom: zoom || 1 + }; + }); + spyOn(scope.scrollView, 'getValues').andCallFake(function() { + return scrollValues; + }); } it('should set x and y with historyData.scrollValues passed in through $viewContentLoaded', function() { compileWithParent(); - spyOn(scope.scrollView, 'scrollTo'); var scrollValues = { top: 40, left: -20, zoom: 3 }; scope.$broadcast('$viewContentLoaded', { scrollValues: scrollValues @@ -100,7 +112,6 @@ describe('Ionic Content directive', function() { it('should set null with historyData.scrollValues not valid', function() { compileWithParent(); - spyOn(scope.scrollView, 'scrollTo'); var scrollValues = { left: 'bar', top: 'foo' }; scope.$broadcast('$viewContentLoaded', { scrollValues: scrollValues }); timeout.flush();