I am trying to write a test case for one of the components in an application the constructor is as follows.
constructor(private router: Router,
public dialog: MatDialog,
private tlsApiService: TlsApiService,
private ncCutterSheetApiService: NcCutterSheetApiService,
) {
this.outEvent = new EventEmitter<number>();
router.events.forEach((event) => {
if(event instanceof NavigationStart) {
if(this.dialogRef){
this.dialogRef.close()
}
}
// NavigationEnd
// NavigationCancel
// NavigationError
// RoutesRecognized
});
}
when I try to write a mock of the router using jasmine.createSpyObj I am getting this message.
TypeError: router.events.forEach is not a function
I have tried the following ways of creating the spyObject
mockRouter = jasmine.createSpyObj(['events',['forEach']]);
mockRouter = jasmine.createSpyObj('events',['forEach']);
mockRouter = jasmine.createSpyObj(['events','forEach']);
I keep getting the same error. I have done google searches trying to find what I need and so far I have not found what I am looking for to get this to work. Any suggestions will be welcomed.