Skip to content

Angular 18 migration issue: Replace deprecated Http modules doesn't work correctly #58536

@pishchela

Description

@pishchela

Command

update

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Running ng update on an Angular 17 project with unit tests containing both HttpClientModule and HttpClientTestingModule. Result of the "Replace deprecated HTTP modules with provider functions" schematics is invalid.

Before:

import { HttpClientModule } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('AppComponent', () => {

  beforeEach(async (): void => {
    await TestBed.configureTestingModule({
      imports: [
        HttpClientModule,
        HttpClientTestingModule,
        AppComponent,
      ],
      providers: [
      ],
    }).compileComponents();
  });
});

After:

import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideHttpClientTesting } from '@angular/common/http/testing';

describe('AppComponent', () => {

  beforeEach(async (): void => {
    await TestBed.configureTestingModule({
    imports: [HttpClientModule,
        AppComponent],
    providers: [
        provideHttpClient(withInterceptorsFromDi()),
        provideHttpClientTesting()
    ]
}{
    imports: [HttpClientTestingModule,
        AppComponent],
    providers: [
        provideHttpClient(withInterceptorsFromDi())
    ]
}).compileComponents();
  });
}
});

Expected result would be TestBed.configureTestingModule with single object inside and replaced deprecated modules with provider functions

Minimal Reproduction

  1. command run: npx @angular/cli@17 new angular-18-migration-issues
  2. Use both HttpClientModule and HttpClientTestingModule in TestBed.configureTestingModule
  3. command run: ng update @angular/core@18 @angular/cli@18

Example commit

Exception or Error

No response

Your Environment

Angular CLI: 18.2.8
Node: 22.11.0
Package Manager: npm 10.9.0
OS: darwin arm64

Angular: 18.2.8
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1802.8
@angular-devkit/build-angular 18.2.8
@angular-devkit/core 18.2.8
@angular-devkit/schematics 18.2.8
@schematics/angular 18.2.8
rxjs 7.8.1
typescript 5.5.4
zone.js 0.14.10

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: common/httpIssues related to HTTP and HTTP Client

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions