Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度及;Jasmine:如何在服务名称中插入点_Angularjs_Testing - Fatal编程技术网

Angularjs 角度及;Jasmine:如何在服务名称中插入点

Angularjs 角度及;Jasmine:如何在服务名称中插入点,angularjs,testing,Angularjs,Testing,我有一个这样定义的服务: angular.module("myApp") .factory("myService.foo", function () { // utterly delightful code }); 我用Karma和Jasmine来测试。在测试中,我的大多数服务器测试都是这样做的: describe('Service: someService', function () { // load the service's module beforeEach

我有一个这样定义的服务:

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”的服务执行相同操作时,它会抛出一个错误(当然):


由于点语法的明显问题,angular无法推断服务名称。如何注入此服务来测试它?是否缺少其他语法?

您可以使用数组表示法,例如:

var _myService;
beforeEach(inject(['myService.foo', function (myService) {
    _myService = myService;
}]));
注(来源):

数组中字符串标识符的顺序非常重要 与参数签名中参数名称的顺序相同 工厂功能。除非依赖项是从 函数签名,就是这个带有ID及其顺序的数组 injector用于确定要执行的服务和顺序 注射

var _myService;
beforeEach(inject(['myService.foo', function (myService) {
    _myService = myService;
}]));