angularjs - Testing output of $q.all in angular controller -



angularjs - Testing output of $q.all in angular controller -

my controller below (pls note had not shown dependencies sake of simplicity):

.controller('demo',function(){ fn1(){ var defereed = $q.defer; /* fetch info server , 1 time info fetched perform resolve */ homecoming deferred.promise; } fn2(){ var defereed = $q.defer; /* fetch info server , 1 time info fetched perform resolve*/ homecoming deferred.promise; } fun3() { /*makes server side calls , updates view*/} $q.all([fn1(),fn2()] .then(function(result){ if (result[0]) { fn3();} }); }

under such circumstances have having hard time testing whether fn3() called. not able fn1() , fn2() resolve can test fn3()

any tips appreciated.

finally figuered solution .. interested check plnkr: http://plnkr.co/hkaqdh

describe('testing: mainctrl', function() { var $scope = null; var ctrl = null; var mockinitservice; var defer1,defer2; var $q; beforeeach(module('plunker')); beforeeach(inject(function($rootscope, $controller,$q) { $scope = $rootscope.$new(); $q = $q; mockinitservice = { fn1: function(){}, fn2: function(){}, fn3: function(){} }; defer1 = $q.defer(); defer2 = $q.defer(); spyon(mockinitservice,'fn1').and.returnvalue(defer1.promise); spyon(mockinitservice,'fn2').and.returnvalue(defer2.promise); spyon(mockinitservice,'fn3'); createcontroller = function() { homecoming $controller('mainctrl', { $scope: $scope, initservice: mockinitservice }); } })); it('should phone call initservice.fn3', function() { ctrl = createcontroller(); defer1.resolve(); defer2.resolve(); $scope.$digest(); expect(mockinitservice.fn3).tohavebeencalled(); }); });

angularjs jasmine

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -