Given this component that creates a service locally
@Component({
<removed for clarity>
providers: [
{ provide: 'IMyService', useClass: MyService },
]
})
export class MyComponent implements OnInit, OnDestroy, AfterViewInit
{
constructor(private data: IMyService){}
}
I've been trying to supply the service in the unit test, something like this
beforeEach(async(() =>
{
TestBed.configureTestingModule({
declarations: [MyComponent],
providers: [
{ provide: 'IMyService', useClass: MockMyService },
]
})
/*
.overrideProvider('IMyService', { useValue: MockMyService })
.overrideComponent(MyComponent, {
set: {
providers: [
{ provide: 'IMyService', useClass: MockMyService }
]
}
})
*/
.compileComponents();
The commented out bits being things I've tried.
But I constantly get this message
Failed: Can't resolve all parameters for MyComponent: (?)
What am I missing here?
IMyService
. Are you importing from right path ? – Tacita