Browse Source

Refactor test setup to use provideHttpClient APIs

Replaces HttpClientTestingModule imports with provideHttpClient and provideHttpClientTesting in test files for improved Angular test setup. This aligns with updated Angular best practices for providing HTTP client dependencies.
pull/23460/head
Fahri Gedik 4 months ago
parent
commit
39350f52c0
  1. 6
      npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts
  2. 15
      npm/ng-packs/packages/core/src/lib/tests/permission.guard.spec.ts
  3. 6
      npm/ng-packs/packages/oauth/src/lib/tests/auth.guard.spec.ts

6
npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts

@ -1,4 +1,5 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { of } from 'rxjs';
import { AbpApplicationConfigurationService } from '../proxy/volo/abp/asp-net-core/mvc/application-configurations/abp-application-configuration.service';
@ -121,8 +122,9 @@ describe('ConfigStateService', () => {
const createService = createServiceFactory({
service: ConfigStateService,
imports: [HttpClientTestingModule],
providers: [
provideHttpClient(),
provideHttpClientTesting(),
{ provide: CORE_OPTIONS, useValue: { skipGetAppConfiguration: true } },
{
provide: AbpApplicationConfigurationService,

15
npm/ng-packs/packages/core/src/lib/tests/permission.guard.spec.ts

@ -1,19 +1,15 @@
import { APP_BASE_HREF } from '@angular/common';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import { provideRouter, Route, Router, RouterModule } from '@angular/router';
import { provideRouter, Route, Router } from '@angular/router';
import { createSpyObject, SpyObject } from '@ngneat/spectator/jest';
import { of } from 'rxjs';
import { permissionGuard } from '../guards/permission.guard';
import { HttpErrorReporterService } from '../services/http-error-reporter.service';
import { PermissionService } from '../services/permission.service';
import { RoutesService } from '../services/routes.service';
import { CORE_OPTIONS } from '../tokens/options.token';
import { IncludeLocalizationResourcesProvider, provideAbpCore, withOptions } from '../providers';
import { provideAbpCore, withOptions } from '../providers';
import { TestBed } from '@angular/core/testing';
import { RouterTestingHarness } from '@angular/router/testing';
import { OTHERS_GROUP } from '../tokens';
import { SORT_COMPARE_FUNC, compareFuncFactory } from '../tokens/compare-func.token';
import { AuthService } from '../abstracts';
@Component({ template: '' })
@ -50,8 +46,9 @@ describe('authGuard', () => {
permissionService = createSpyObject(PermissionService);
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
provideHttpClient(),
provideHttpClientTesting(),
{ provide: AuthService, useValue: mockOAuthService },
{ provide: PermissionService, useValue: permissionService },
{ provide: HttpErrorReporterService, useValue: httpErrorReporter },

6
npm/ng-packs/packages/oauth/src/lib/tests/auth.guard.spec.ts

@ -9,7 +9,8 @@ import {
RouterStateSnapshot,
provideRouter,
} from '@angular/router';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { provideHttpClientTesting } from '@angular/common/http/testing';
import { provideHttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { RouterTestingHarness } from '@angular/router/testing';
@ -64,8 +65,9 @@ describe('authGuard', () => {
oAuthService = createSpyObject(OAuthService);
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
provideHttpClient(),
provideHttpClientTesting(),
{ provide: AuthService, useValue: authService },
{ provide: OAuthService, useValue: oAuthService },
provideRouter(routes),

Loading…
Cancel
Save