问题
如何ActivatedRoutes
在我的单元测试中模拟?
服务:
constructor(
private route: ActivatedRoute,
private knowledgeModelService: KnowledgeModelService
) {
route.params.pipe(map(p => p.modelId)).subscribe((modelId) => {
this.modelId = modelId;
});
}
我的单元测试:
带模拟课
class ActivatedRouteMock {
// params = of([{modelId: 'test1'}]);
params = { paramMap: of( convertToParamMap( { modelId: 'test1' } ) ) }
}
...
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ StatsComponent ],
providers: [
{
provide: ActivatedRoute, useClass: ActivatedRouteMock
},
我试过差异。方法来自:
Angular 4 - 失败:无法解析 ActivatedRoute 的所有参数:(?, ?, ?, ?, ?, ?, ?, ?)
但我没有得到任何地方。
呃:
route.params.pipe is not a function