【发布时间】:2022-12-01 20:21:51
【问题描述】:
Here is my method in ts file: this method called upon click on any of the td from the table. event passing the row data. null is accpeted.
initiateDetailsView(detailsData): void {
this.personalDataService.userDetails$.next(detailsData);
this.router.navigate(['./personnel-details'], {
relativeTo: this.activatedRoute,
});
}
I am trying to do the testing the same method like this:
it('should call initiateDetailsView list click and need to redirect to profile page', fakeAsync(async () => {
const initiateDetailsView = spyOn(
component,
'initiateDetailsView'
).and.callThrough();
component.tableSchema = testHFSTaleSchema;
component.setPersonnelList();
tick(1000);
const tds = fixture.debugElement.query(By.css('td'));
tds.nativeElement.click(null);
expect(initiateDetailsView).toHaveBeenCalledWith(null);
}));
but getting an error as:
ERROR: 'ERROR', TypeError: Cannot read properties of undefined (reading '_lastPathIndex')
the above error thrown from router. But do not know have to address this issue in test. any one please help me here? how can test the method which has the router navigate?
【问题讨论】:
标签: angular angular-routing angular-test