angularunit-testingtestingkarma-jasmine

TS2305: Module '@angular/core/testing' has no exported member async


I updated angular version from 17 to 18 and because of which some modules are no longer supporter especially in spec.ts files while importing them. Like async from @angular/core/testing and **provideRouterTesting **from @angular/router/testing and **HttpClientTestingModule **from @angular/common/http/testing. The exact error messages are as follows

@angular/router/testing' has no exported member provideRouterTesting TS2305: Module '@angular/core/testing' has no exported member async TS6385: HttpClientTestingModule is deprecated.

I need to know the alternatives for these modules. It will be helpful if anyone can update the alternative modules for these.


Solution

  • The fix for

    HttpClientTestingModule is deprecated.

    Is to use provideHttpClientTesting

    We should also include provideHttpClient


    You can try fixing

    '@angular/core/testing' has no exported member async

    With using waitForAsync


    You can try fixing

    @angular/router/testing' has no exported member provideRouterTesting

    With using RouterTestingModule.withRoutes (Non standalone)

    Or

    provideRouter and provideLocationMocks combined (Standalone).

    Article on Angular Router Testing