user1323435 user1323435 - 1 year ago 80
AngularJS Question

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

The following is in my controller:

$scope.addRangesAndSquare = function() {

And I want to spy on
, so that when
is called so is

it('expect addLeftRange to be called after calling addRangesAndSquare', function () {
spyOn(scope ,'addRangesAndSquare');
spyOn(scope, 'addLeftRange');

How can this be done?

Answer Source

by default, when you use spyOn with jasmine, it mocks that function and doesn't actually execute anything within it. If you want to test further function calls within, you'll need to call .andCallThrough(), like so:

spyOn($scope, 'addRangesAndSquare').andCallThrough();

that should do it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download