Angular 2 beforeEachProviders 在测试中因注入器失败

Angular 2 beforeEachProviders fail with Injector in tests

当我尝试在测试中将 Injector 传递给 beforeEachProviders 时,出现以下错误。

Failed: Cannot resolve all parameters for 'Injector'(?, ?, ?, ?, ?).
Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'Injector' is decorated with Injectable.

我使用的代码

import { Injector } from 'angular2/core';

describe(() => {
  beforeEachProviders(() => [Injector]);
});

少了什么?我应该给提供者什么才能实例化它?

我认为您不需要在提供程序中配置 Injector 来进行测试。这个class的一个实例可以直接注入到你的测试中...

这是我的一个测试中的内容(Injector 没有 "explicit" 提供程序),我可以稍后将其注入测试:

import {it, describe, expect, beforeEach, inject, beforeEachProviders} from 'angular2/testing';
import {HTTP_PROVIDERS, XHRBackend, Response, ResponseOptions} from 'angular2/http';
import {MockBackend, MockConnection} from 'angular2/http/testing';
import {provide, Injector} from 'angular2/core';
import {HttpService} from "./http-service";

describe('HttpService Tests', () => {
  beforeEachProviders(() => {
    return [
      HTTP_PROVIDERS,
      provide(XHRBackend, { useClass: MockBackend }),
      HttpService
    ];
  });

  it('Should return a list of dogs', inject(
         [XHRBackend, HttpService, Injector],
         (mockBackend, httpService, injector) => {
    console.log(injector); // <----- Not null
  });
});