javascript - Jasmine - How to spy on a function call within a function? -


the following in controller:

$scope.addrangesandsquare = function() {     $scope.addleftrange();     $scope.addcentersquare();     $scope.addrightrange(); } 

and want spy on $scope.addleftrange(), when $scope.addrangesandsquare called $scope.addleftrange():

it('expect addleftrange called after calling addrangesandsquare', function () {     spyon(scope ,'addrangesandsquare');     spyon(scope, 'addleftrange');     scope.addrangesandsquare();     expect(scope.addleftrange).tohavebeencalled(); }); 

how can done?

by default, when use spyon jasmine, mocks function , doesn't execute within it. if want test further function calls within, you'll need call .andcallthrough(), so:

spyon($scope, 'addrangesandsquare').andcallthrough(); 

that should it.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -