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();
});
...