2013-02-18 67 views
1

我有一個指令,它依賴於其中一個服務。它有一個名爲getcustomers()的方法。雖然我試圖測試指令如何注入該服務?如何在指令測試中注入服務

+1

添加除@howderek承諾,我想補充鏈接plunker片段用於測試使用AngularJS和Jasmine:http://plnkr.co/edit/gist:3743008 – 2013-02-18 20:12:51

回答

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....