diff --git a/goldens/public-api/common/http/testing/index.md b/goldens/public-api/common/http/testing/index.md index 1b21c819a0d..e6da6e192ae 100644 --- a/goldens/public-api/common/http/testing/index.md +++ b/goldens/public-api/common/http/testing/index.md @@ -10,6 +10,7 @@ import { HttpRequest } from '@angular/common/http'; import * as i0 from '@angular/core'; import * as i1 from '@angular/common/http'; import { Observer } from 'rxjs'; +import { Provider } from '@angular/core'; // @public export class HttpClientTestingModule { @@ -37,6 +38,9 @@ export abstract class HttpTestingController { }): void; } +// @public (undocumented) +export function provideHttpClientTesting(): Provider[]; + // @public export interface RequestMatch { // (undocumented) diff --git a/packages/common/http/testing/public_api.ts b/packages/common/http/testing/public_api.ts index 886408981b1..b4e3c445c69 100644 --- a/packages/common/http/testing/public_api.ts +++ b/packages/common/http/testing/public_api.ts @@ -8,4 +8,5 @@ export {HttpTestingController, RequestMatch} from './src/api'; export {HttpClientTestingModule} from './src/module'; +export {provideHttpClientTesting} from './src/provider'; export {TestRequest} from './src/request'; diff --git a/packages/common/http/testing/src/module.ts b/packages/common/http/testing/src/module.ts index f1c76c0cfac..b5f73641bc8 100644 --- a/packages/common/http/testing/src/module.ts +++ b/packages/common/http/testing/src/module.ts @@ -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 { diff --git a/packages/common/http/testing/src/provider.ts b/packages/common/http/testing/src/provider.ts new file mode 100644 index 00000000000..7676a51818f --- /dev/null +++ b/packages/common/http/testing/src/provider.ts @@ -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}, + ]; +}