我有一个指令,它依赖于其中一个服务。它有一个名为getcustomers()的方法。当我试图测试指令时如何注入该服务?
答案 0 :(得分: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....