NullInjectorError: No provider for ActivatedRoute
//Unit test
//It is pretty straightforward to mock the ActivatedRoute in the User component test file. All we have to do is to edit the providers list as follows:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ UserComponent ],
imports: [
RouterTestingModule,
HttpClientTestingModule
// ... whatever other module you have
],
providers:
[
{
provide: ActivatedRoute,
useValue: {
snapshot: {params: {id: '24fkzrw3487943uf358lovd'}}
}
}
]
})
.compileComponents();
}));