Ionic 5 Unit Tests with routerLink

I’m developing an Ionic 5 App. I was testing a component like this:

beforeEach(async(() => {
      declarations: [HomePage],
      imports: [MocksModule, IonicModule.forRoot()]

    fixture = TestBed.createComponent(HomePage);
    component = fixture.componentInstance;

It was working fine but after I added:

<ion-button routerLink="/settings">
    <ion-icon slot="icon-only" name="settings-outline"></ion-icon>

The test fails with:

Failed: R3InjectorError(DynamicTestModule)[NavController -> UrlSerializer -> UrlSerializer]: 
  NullInjectorError: No provider for UrlSerializer!

In MocksModule I export a stub directive as recommended in the Angular docs I believe the error is related to the implementation of RouterLink inside IonicModule.

You just need to add RouterTestingModule to your test providers array.