1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

HttpClientTestingModule is deprecated, how to replace it?

Discussão em 'Angular' iniciado por kellermat, Setembro 2, 2025.

  1. kellermat

    kellermat Guest

    After upgrading my application to Angular 18.0.4, my test classes say:

    'HttpClientTestingModule' is deprecated. Add provideHttpClientTesting() to your providers instead.

    Therefore I adapted my code as follows:

    await TestBed.configureTestingModule(
    {
    imports: [
    AssetDetailsComponent,
    ],
    providers: [
    // replacement for HttpClientTestingModule:
    provideHttpClientTesting()
    ]
    })
    .compileComponents();


    However, when I run the tests, I get the following error:

    NullInjectorError: R3InjectorError(Standalone[AssetDetailsComponent])[InventoryActionService -> InventoryActionService -> _HttpClient -> _HttpClient]:
    NullInjectorError: No provider for _HttpClient!


    If I use provideHttpClient() instead of provideHttpClientTesting() it works, yet I doubt that this is best practice. What is the correct solution to this issue?

    Continue reading...

Compartilhe esta Página