1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular test harness failing with timeout when API call is having timeout

Discussão em 'Angular' iniciado por Arnab Mukherjee, Maio 14, 2025.

  1. Trying to UT a component with test harness, here the UT below:

    it('sample ut', async () => {
    // mocking service
    spyOn(service, 'getLinkedIssesData').and.returnValue(of(rtConsolidatedLinkedIssesTableData));
    // initializing component
    component.ngOnInit();

    const issueTypeFilter = await loader.getHarness<MatSelectHarness>(MatSelectHarness.with({
    selector: '#issuetype-filter'}));
    const table = await loader.getHarness<MatTableHarness>(MatTableHarness.with({selector: '#data-table'}));
    await issueTypeFilter.clickOptions();
    expect((await table.getRows()).length).toBe(3);
    });


    I have a service method, check below:

    public getLinkedIssesData(releaseName: string): Observable<RtLinkedIssuesDetails[]>{
    console.log('RtQueryServiceService:getLinkedIssesData request for release:', releaseName);
    return this.http.get<any>(
    RestServerRT.CONSOLIDATED_LINKED_ISSUED_DATA.replace('{release-name}', releaseName), {headers: this.headers})
    .pipe(
    timeout({
    each: API_CALL_TIMEOUT_MS,
    with: () => throwError(() => new RtDbQueryTimeout('more than:'+API_CALL_TIMEOUT_MS+'ms'))
    }),
    catchError(err => {
    console.error('Issue seen in endpoint:', RestServerRT.CONSOLIDATED_LINKED_ISSUED_DATA, ', details:', err);
    return throwError(
    () => new RtRestApiCallException('Issue seen in endpoint: '+ RestServerRT.CONSOLIDATED_LINKED_ISSUED_DATA));
    }),
    map(linkedIssuesData => this.generateRtLinkedIssuesDetailsObjects(linkedIssuesData))
    );
    }


    Test Harness is failing with

    Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
    at <Jasmine>


    Test is going fine when timeout is commented in service. Timeout is required as we need show some error message if rest is not responding within a timeframe.

    Continue reading...

Compartilhe esta Página