我有一个这样定义的服务:
angular.module("myApp")
.factory("myService.foo", function () {
// utterly delightful code
});
我正在使用 Karma 和 Jasmine 进行测试。在测试中,我对大多数服务器测试都在做这样的事情:
describe('Service: someService', function () {
// load the service's module
beforeEach(module('myApp'));
// instantiate service
var _someService;
beforeEach(inject([function (someService) {
_someService = someService;
}]));
it('should do something', function () {
expect(!!_someService).toBe(true);
});
});
当我尝试对名为“myService.foo”之类的服务执行相同操作时,它会引发错误(当然):
describe('Service: myService.foo', function () {
// load the service's module
beforeEach(module('myApp'));
// instantiate service
var _myService;
beforeEach(inject([function (myService.foo) {
_myService = myService.foo;
}]));
it('should do something', function () {
expect(!!_myService).toBe(true);
});
});
由于点语法的明显问题使得 Angular 无法推断服务名称。我怎样才能注入这个服务来测试它?我缺少一些替代语法吗?