I'm trying to test that two async functions. The problem is that one of the functions is called every 10 seconds automatically. I tried to use tick() or flush() but I still get the same error: 1 periodic timer(s) still in the queue. How can I resolve it? My code:
ngOnInit(): void {
const dialogRef = this.openProgressDialog();
this.getSubscription = this.getAll();
dialogRef.close();
this.postSubscription = interval(10000).subscribe(() => {
this.sendAll();
this.dataSource.data = this.jobs;
this.table.renderRows();
});
}
The test:
test("test", fakeAsync(() => {
const getSpy = spyOn(otdRepositoryMock, "getAll").and.returnValue(of(jobs));
const getSubscribeSpy = spyOn(otdRepositoryMock.getAll(), "subscribe");
const postSpy = spyOn(otdRepositoryMock, "sendAll").and.returnValue(of(jobs));
const postSubscribeSpy = spyOn(otdRepositoryMock.sendAll([2]), "subscribe");
component.ngOnInit();
//tick();
//flush();
expect(getSpy).toHaveBeenCalled();
expect(getSubscribeSpy).toHaveBeenCalled();
expect(postSpy).toHaveBeenCalled();
expect(postSubscribeSpy).toHaveBeenCalled();
}));