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
Post a Comment