1

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.

1
  • Are you using npm instal --force?
    – André
    Commented Jun 27 at 6:37

1 Answer 1

1

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

3
  • 1
    Thank you Naren, waitForAsync worked but the remaining two are showing errors while runnning them. I got Unexpected value 'provideRouter' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation. . If you have any suggestions regarding it. Commented Jul 1 at 6:59
  • 1
    We should also include provideHttpClient(), along with provideHttpClientTesting(). Then it worked for me. Commented Jul 1 at 12:25
  • 1
    In some cases, we should also include RouterLink along with provideRouter. Commented Jul 3 at 10:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.