How to mock angular.element.injector().get;

I have controller code like this in an angularjs file...

    function sendAnalytics(searchParams) {
        var analyticServiceCall = angular.element(document.body).injector().get('SomeElement');
     };

When I run test cases attached with the above controller I get the following error

 * TypeError: Cannot call method "get" of undefined in http://localhost:46309/src/soemFolder/someController.js (line XYZ)

What I am understanding is, I need to mock angular.element(document.body).injector().get function but how to do it?

Upvotes: 0

Views: 519

Answers (1)

Varvara Sandakova
Varvara Sandakova

Reputation: 139

beforeEach(inject(function($injector) {
  angular.element.fn.extend({ injector: function() { return $injector } });
});

You can find more information here

Upvotes: 1

Related Questions