I can not look at angular.element

I have one Jasmine test that constantly fails due to lack of spyOn .

The following test will fail automatically:

 it('simple test', function() { spyOn(angular, 'element'); }); 

Error:

 TypeError: 'undefined' is not an object (evaluating 'angular.element(handle.elem).off') at /Users/geoff/Project/www/components/angular-mocks/angular-mocks.js:1946 at /Users/geoff/Project/www/components/angular-mocks/angular-mocks.js:1977 

This error only occurs with angular.element . spy ing for other angular methods like angular.copy and angular.forEach , do not throw this error. I am using Jasmine 2.0 and Angular ~ 1.3. Any tips to fix this problem will be appreciated.

+5
source share
1 answer

You need to allow access to the real object.

 spyOn(angular, 'element').and.callThrough(); 

The code tries to access the property of the return value, but the spy returns nothing. You cannot access .off in an undefined object!

+6
source

All Articles