mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
`HttpClient` uses the `PendingTasks` service to contribute to
application stability. This was added in v16 to support SSR without
relying on an infinite `setTimeout` with ZoneJS like it did pre-v16.
Prior to version 16, this was also only done on the server and did not
affect clients or unit tests (28c68f709c).
Today, `PendingTasks` contribute to `ApplicationRef.isStable` but do not
contribute to the stability of `ComponentFixture`. This divergence in
stability behavior was not intended and we plan to make these two
stability indicators the same again, like they were when it was solely
based on the state of the Zone.
By aligning the two behaviors again, this would include all pending
tasks in the stability of fixtures. After investigation, this seems
likely to be a pretty large breaking change. Tests appear to quite often use
`await fixture.whenStable` when there are unfinished requests that have
not been mocked or flushed.
This change prevents request in `HttpClient` from contributing to
stability through the `PendingTasks` automatically but only when using
`HttpClientTesting`. In this scenario, requests need to be expected and
flushed manually for them to resolve. When the test backend and controllers
aren't used, requests should resolve on their own so `await fixture.whenStable`
shouldn't be particularly affected or problematic.
PR Close #54974
22 lines
745 B
TypeScript
22 lines
745 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {HttpBackend, ɵREQUESTS_CONTRIBUTE_TO_STABILITY} from '@angular/common/http';
|
|
import {Provider} from '@angular/core';
|
|
|
|
import {HttpTestingController} from './api';
|
|
import {HttpClientTestingBackend} from './backend';
|
|
|
|
export function provideHttpClientTesting(): Provider[] {
|
|
return [
|
|
HttpClientTestingBackend,
|
|
{provide: HttpBackend, useExisting: HttpClientTestingBackend},
|
|
{provide: HttpTestingController, useExisting: HttpClientTestingBackend},
|
|
{provide: ɵREQUESTS_CONTRIBUTE_TO_STABILITY, useValue: false},
|
|
];
|
|
}
|