angularjs - Test if function has been called inside $scope.$watch -


i'm trying figure out how test karma jasmine if function executed inside $watch conditions need.

here in controller. $watch contains couple of condition.

 $scope.$watch('player', function (newval, oldval) {     if (oldval && newval != undefined && newval != oldval) {         if (newval.email == oldval.email && newval.emwallet == oldval.emwallet)             $scope.savesettings();     } }, true) 

this part of test

it('when player property changed savesettings calls', function () {      var sspy = spyon(scope, "savesettings");     expect(scope.player.email).toequal('');     expect(scope.player.emwallet).toequal('');      expect(scope.player.balance).toequal(10.0000);      //change player balance     scope.player.balance = 10.0304;     scope.$apply();      expect(scope.player.email).toequal('');     expect(scope.player.emwallet).toequal('');      expect(sspy).tohavebeencalled();  }); 

in test above i'm changing property outside condition player.email , player.emwallet still same , expect call of savesettings() function inside, "sspy has never been called" error.

i appreciate lot if point me right direction.

update: when change actual value scope.player.balance = 10.0304; in code, function fires, test not pass


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -