给定这个在本地创建服务的组件
@Component({
<removed for clarity>
providers: [
{ provide: 'IMyService', useClass: MyService },
]
})
export class MyComponent implements OnInit, OnDestroy, AfterViewInit
{
constructor(private data: IMyService){}
}
我一直在尝试在单元测试中提供服务,就像这样
beforeEach(async(() =>
{
TestBed.configureTestingModule({
declarations: [MyComponent],
providers: [
{ provide: 'IMyService', useClass: MockMyService },
]
})
/*
.overrideProvider('IMyService', { useValue: MockMyService })
.overrideComponent(MyComponent, {
set: {
providers: [
{ provide: 'IMyService', useClass: MockMyService }
]
}
})
*/
.compileComponents();
注释掉的部分是我尝试过的东西。
但我不断收到这条消息
Failed: Can't resolve all parameters for MyComponent: (?)
我在这里想念什么?