0
なしプロバイダで失敗します。角度2ユニバーサル、ユニットテストはエラー、私はusung角度2ユニバーサルだのHttp
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Page } from './page';
@Injectable()
export class MyService {
constructor(private http: Http) { }
getPage(id: number): Observable<Page> {
return null;
}
}
ユニットテスト:
import { TestBed, async, inject } from '@angular/core/testing';
import { PageService } from './workflow.service';
describe('Service: Workflow',() => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [WorkflowService]
});
});
it('should ...', inject([PageService], (service: PageService) => {
expect(service).toBeTruthy();
}));
});
私がサービスを持っています
マイアプリモジュール:
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
HomeComponent,
WorkflowComponent
],
imports: [
HttpModule,
UniversalModule, // Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too.
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'workflow/:id', component: WorkflowComponent }
])
]
})
export class AppModule {
}
ユニットテストを実行すると、次のエラーメッセージが表示されます。エラー:Httpのプロバイダがありません! http
モジュールは、app.module内のUniversalModule
は、コメントに示されているとおりにインポートする必要があります。
私は最新の角度ユニバーサルを使用しています。
http
をテストに追加する必要がありますか?
あなたはこのような何かをしようとしたしましたか? (バックエンド:ConnectionBackend、defaultOptions:BaseRequestOptions)=> { :Http(backend、defaultOptions); return新しいHttpを返します。 }、 deps:[MockBackend、BaseRequestOptions] }、 ] '' – styopdev
@styopdevコメントをいただきありがとうございます。 – shiva