我在更新代码从pre-RC5到RC6时遇到了类似的问题。进一步解释Joe W上面的答案,我替换了这段代码:
import { ReflectiveInjector, provide } from '@angular/core';
import { HTTP_PROVIDERS, RequestOptions } from '@angular/http';
export function main() {
describe('My Test', () => {
let myService: MyService;
beforeAll(() => {
let injector = ReflectiveInjector.resolveAndCreate([
HTTP_PROVIDERS,
provide(RequestOptions, { useValue: getRequestOptions() }),
MyService
]);
myService = injector.get(MyService);
});
it('should be instantiated by the injector', () => {
expect(myService).toBeDefined();
});
...
使用此RC6代码(我猜应该也适用于RC5):
import { TestBed } from '@angular/core/testing';
import { HttpModule, RequestOptions } from '@angular/http';
export function main() {
describe('My Test', () => {
let myService: MyService;
beforeAll(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
{ provide: RequestOptions, useValue: getRequestOptions() },
MyService
]
});
myService = TestBed.get(MyService);
});
it('should be instantiated by the testbed', () => {
expect(myService).toBeDefined();
});
...
HttpModule
取代。 - micronyks