Skip to content Skip to sidebar Skip to footer

$scope Exists On Browser Debugger, But Does Not Exist In Terminal

I have a directive that is depended on a controller which gets data from an api though Ajax call. It works correctly. I am trying to test it using jasmine and the strange issue is

Solution 1:

how about ?

it('should ......', function () {
  expect(element.scope().measurementScroll).toBe(true);
});

UPDATE:

and I think you also need to use the andCallThrough method on the _.defer

spyOn(obj, 'method').andCallThrough()

Solution 2:

Edit Seems that the bellow solution is a "Perfect wrong case". However the tests passes they never fall, even if they are wrong.

Wrong solution The test passed after altering the following:

it('should ......', function () {
    scope.$evalAsync(function() {
      expect(scope.measurementScroll).toBe(true);
    });
  });

Update: Right Solution

The right solution for this problem was solved by @Michal Charemza in this question - How to test _.defer() using Jasmine, AngularJs

Post a Comment for "$scope Exists On Browser Debugger, But Does Not Exist In Terminal"