I'm trying to test a component.ts:
import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/common';
...
ngOnInit(): void {
this.route.params.forEach((params: Params) => {
let id = +params['id'];
...
}
the spec.ts code below:
describe('MyDetailComponent', () => {
beforeEach( async(() => {
addMatchers();
TestBed.configureTestingModule({
imports: [ MaterialModule, FormsModule ],
declarations: [ MyDetailComponent ],
providers: [
...
{ provide: RequestOptions, useClass: RequestOptionsStub },
{ provide: ActivatedRoute, useClass: RouterStub },
{ provide: Location },
{ provide: XHRBackend, useClass: MockBackend },
AppSettings,
Http,
ConnectionBackend,
Jsonp
]
})
.compileComponents()
.then(createComponent);
}));
and I'm getting the error: Failed: Uncaught (in promise): Error: Error in :0:0 caused by: Cannot read property 'forEach' of undefined TypeError: Cannot read property 'forEach' of undefined
How to fix this?