We have a specific set of tests of our Angular application that requires Jasmine to connect/authenticate and call our ASP.NET Core Web API. As we have numerous UI tests setup (so these are not duplicated in say an Integration test), the requirement is to allow the UI tests to run against mocked as well as real data. The problem is that the connectClient method never seems to complete (see "connectClient:never gets here" in the connectClient code at the bottom of this question). The test looks like it passes but for some unknown reason after the http.post('.../connect/token') request the rest of the code in the connectClient method (and the setup in the Jasmine test - see "Jasmine setup:never gets here" in the Jasmine test code) doesn't run. It may be timing-out (I've tried setting "jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000;", adding "done()", etc but doesn't make any difference) however I don't get any error message indicating the timeout. I've tried replacing the connectClient call with a setTimeout (for 10 seconds) and the process waits and executes as you expect (continues on with the rest of the code). The Jasmine tests looks like the following uiTestAuthService = TestBed.inject(UiTestAuthService) as jasmine.SpyObj<UiTestAuthService>; mockData = await mockDataService.getDynamicReportData(uiTestAuthService); debugger; //<<-- !! Jasmine setup:never gets here !! spyOn(mockCommonService, 'getReportData').and.returnValue(mockData); ... beforeEach(async () => { //jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000000; fixture = TestBed.createComponent(ComponentToBeTested); component = fixture.componentInstance; await fixture.whenStable(); }); ... it('should render correctly', fakeAsync(() => { component = fixture.componentInstance; expect(component).toBeTruthy(); })); The data service is as follows export class MockDataService { async getDynamicReportData(uiTestAuthService: UiTestAuthService, myReportTypeId: any): Promise<any> { var http: HttpClient; var token; [token, http] = await uiTestAuthService.connectClient( 'https://identity-server.my-domain.com', 'client_credentials', 'my-client-id', 'my-client-secret' ); if (token) { var url = 'https://api.my-domain.com'; var reportTypeId = 9999; let apiUrl = `${url}/api/Report/${reportTypeId}` var json = JSON.parse('{"MyVariable1":"my-value-1","MyVariable2":"my-value-2",...}') const headers = new HttpHeaders().set('Authorization', `Bearer ${token}`); return http.post(apiUrl, JSON.stringify(json), { headers }).pipe(map((resp: any) => { return Promise.resolve(resp.Result.Data); })); } } } The connection client (connectClient) service is as follows export class UiTestAuthService { http: HttpClient; constructor( httpClient: HttpClient ) { this.http = httpClient; } async connectClient( authBaseAddress: string, grant_type: string, client_id: string, client_secret: string ): Promise<[string, HttpClient] | null> { const form = new HttpParams() .set('grant_type', grant_type) .set('client_id', client_id) .set('client_secret', client_secret); let retry = false; let retryCount = 0; let jsonContent: any = null; var _this = this; do { try { const response = await firstValueFrom( _this.http.post<any>(`${authBaseAddress}/connect/token`, form.toString(), { headers: new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' }) }) .pipe( catchError(error => { console.error('Error during token retrieval:', error); return throwError(() => new Error('Failed to get authentication token')); }) ) ) debugger; //<<-- !! connectClient:never gets here !! jsonContent = response; retry = false; } catch (error) { console.error(`An error occurred while acquiring a token\nTime: ${new Date()}\nError:`, error); retry = true; retryCount++; await new Promise(res => setTimeout(res, 30000)); // wait 30 seconds } } while (retry && retryCount < 3); if (!jsonContent) { console.warn('Cancelling attempt to contact the report service.'); return null; } const accessToken = jsonContent.access_token; return Promise.resolve([accessToken, _this.http]); } } Continue reading...