feat(http): introduce provideHttpClientTesting provider function (#47502)

This commit introduces the `provideHttpClientTesting()` function as an
alternative to the `HttpClientTestingModule` (in fact, the NgModule is
converted internally to just use the new provider function).

PR Close #47502
This commit is contained in:
Alex Rickabaugh
2022-09-21 13:40:25 -07:00
committed by Jessica Janiuk
parent 67ef8b19b3
commit 84d0d33c35
4 changed files with 30 additions and 6 deletions
+3 -6
View File
@@ -6,11 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import {HttpBackend, HttpClientModule} from '@angular/common/http';
import {HttpClientModule} from '@angular/common/http';
import {NgModule} from '@angular/core';
import {HttpTestingController} from './api';
import {HttpClientTestingBackend} from './backend';
import {provideHttpClientTesting} from './provider';
/**
@@ -25,9 +24,7 @@ import {HttpClientTestingBackend} from './backend';
HttpClientModule,
],
providers: [
HttpClientTestingBackend,
{provide: HttpBackend, useExisting: HttpClientTestingBackend},
{provide: HttpTestingController, useExisting: HttpClientTestingBackend},
provideHttpClientTesting(),
],
})
export class HttpClientTestingModule {
@@ -0,0 +1,22 @@
/**
* @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, HttpClientModule} from '@angular/common/http';
import {NgModule, 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},
];
}