Skip to content

Commit

Permalink
feat(http): introduce provideHttpClientTesting provider function (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
alxhub authored and thePunderWoman committed Oct 6, 2022
1 parent 67ef8b1 commit 84d0d33
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions goldens/public-api/common/http/testing/index.md
Expand Up @@ -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 {
Expand Down Expand Up @@ -37,6 +38,9 @@ export abstract class HttpTestingController {
}): void;
}

// @public (undocumented)
export function provideHttpClientTesting(): Provider[];

// @public
export interface RequestMatch {
// (undocumented)
Expand Down
1 change: 1 addition & 0 deletions packages/common/http/testing/public_api.ts
Expand Up @@ -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';
9 changes: 3 additions & 6 deletions packages/common/http/testing/src/module.ts
Expand Up @@ -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';


/**
Expand All @@ -25,9 +24,7 @@ import {HttpClientTestingBackend} from './backend';
HttpClientModule,
],
providers: [
HttpClientTestingBackend,
{provide: HttpBackend, useExisting: HttpClientTestingBackend},
{provide: HttpTestingController, useExisting: HttpClientTestingBackend},
provideHttpClientTesting(),
],
})
export class HttpClientTestingModule {
Expand Down
22 changes: 22 additions & 0 deletions 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},
];
}

0 comments on commit 84d0d33

Please sign in to comment.