refactor(http): Don't log fetch warning in tests. (#59049)

Prior to this commit, we were logging the `NOT_USING_FETCH_BACKEND_IN_SSR` error when `provideHttpTestingClient` and `PLATFORM_ID` were provided.

fixes #59028

PR Close #59049
This commit is contained in:
Matthieu Riegler 2024-12-04 17:56:21 +01:00 committed by Alex Rickabaugh
parent ae0802d63c
commit ffae7df6e8
2 changed files with 13 additions and 1 deletions

View file

@ -276,7 +276,14 @@ export class HttpInterceptorHandler extends HttpHandler {
// a warning otherwise.
if ((typeof ngDevMode === 'undefined' || ngDevMode) && !fetchBackendWarningDisplayed) {
const isServer = isPlatformServer(injector.get(PLATFORM_ID));
if (isServer && !(this.backend instanceof FetchBackend)) {
// This flag is necessary because provideHttpClientTesting() overrides the backend
// even if `withFetch()` is used within the test. When the testing HTTP backend is provided,
// no HTTP calls are actually performed during the test, so producing a warning would be
// misleading.
const isTestingBackend = (this.backend as any).isTestingBackend;
if (isServer && !(this.backend instanceof FetchBackend) && !isTestingBackend) {
fetchBackendWarningDisplayed = true;
injector
.get(Console)

View file

@ -31,6 +31,11 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
*/
private open: TestRequest[] = [];
/**
* Used when checking if we need to throw the NOT_USING_FETCH_BACKEND_IN_SSR error
*/
private isTestingBackend = true;
/**
* Handle an incoming request by queueing it in the list of open requests.
*/