我正在使用 Angular 2 Universal:
我有一个服务:
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 提供者!
UniversalModule
如注释中所示,在 app.module 中应该 http
已经导入模块。
我正在使用最新的 Angular 通用。
我应该http
在测试中添加吗?