1

我有一个依赖于其中一项服务的指令。它有一个名为 getcustomers() 的方法。当我尝试测试指令时,如何注入该服务?

4

1 回答 1

1
  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....
于 2013-02-18T20:26:56.913 回答