Ducati007
Ducati007

Reputation: 275

How to inject services in directives testing

I have a directive which has a dependency on one of the services. It has a method called getcustomers(). While I am trying to test the directive How do I inject that service?

Upvotes: 1

Views: 331

Answers (1)

Ducati007
Ducati007

Reputation: 275

  var app = angular.module('mymod', []);
        app.service('myser', myservicename);
        app.directive('mydir', mydir);

//Before Beforeeach(inject) 
beforeEach(module('mymod'));  //This loads all the necessary dependencies for your directive


spyOn(myservice, 'methodname').andCallThrough();

That's it..above line mocks the service call and lets you call it....

Upvotes: 1

Related Questions