将模拟注入AngularJS服务
我写了一个AngularJS服务,我想对其进行单元测试。 angular.module('myServiceProvider', ['fooServiceProvider', 'barServiceProvider']). factory('myService', function ($http, fooService, barService) { this.something = function() { // Do something with the injected services }; return this; }); 我的app.js文件已注册: angular .module('myApp', ['fooServiceProvider','barServiceProvider','myServiceProvider'] ) 我可以测试DI是否像这样工作: describe("Using the DI framework", function() { beforeEach(module('fooServiceProvider')); beforeEach(module('barServiceProvider')); beforeEach(module('myServiceProvder')); var service; beforeEach(inject(function(fooService, barService, myService) { service=myService; })); it("can be …