0
所以,我有兩個服務:如何在嘲笑該服務的依賴時測試angualar服務?
// The service I'm testing
angular.module("m").service("myService", function(otherService) { ... })
// the service I'd like to mock while testing
angular.module("m").service("otherService", function() { ... })
describe("my test", function() {
var myService = null;
beforeEach(module('m'));
beforeEach(inject(function($injector) {
///////////////////////////////////////////////////////
// but I want it to get injected with 'otherService'
///////////////////////////////////////////////////////
myService = $injector.get("myService")
})
it ('test myService', function() {
})
})
我想它注入myService
之前模擬出otherService
我測試的myService
在跟進it
功能的實例。