# Ionic 5 Unit Tests with routerLink

**URL:** <https://forum.ionicframework.com/t/ionic-5-unit-tests-with-routerlink/186138>\
**Category:** Ionic Angular\
**Created:** [March 30, 2020, 3:47am UTC](https://forum.ionicframework.com/t/ionic-5-unit-tests-with-routerlink/186138 "2020-03-30T03:47:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexortizl](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@alexortizl](https://forum.ionicframework.com/u/alexortizl)\
**Post date:** [March 30, 2020, 3:47am UTC](https://forum.ionicframework.com/t/ionic-5-unit-tests-with-routerlink/186138/1 "2020-03-30T03:47:10Z")

</div>

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

```auto
beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [HomePage],
      imports: [MocksModule, IonicModule.forRoot()]
    }).compileComponents();

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

```

It was working fine but after I added:

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

```

The test fails with:

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

```

In `MocksModule` I export a stub directive as recommended in the Angular [docs](https://angular.io/guide/testing#components-with-routerlink) I believe the error is related to the implementation of `RouterLink` inside `IonicModule`.

---

<div class="post-metadata">

**Author:** ![rabbitfighter81](https://avatars.discourse-cdn.com/v4/letter/r/2bfe46/32.png) [@rabbitfighter81](https://forum.ionicframework.com/u/rabbitfighter81)\
**Post date:** [June 11, 2020, 9:33pm UTC](https://forum.ionicframework.com/t/ionic-5-unit-tests-with-routerlink/186138/2 "2020-06-11T21:33:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tylerpashigian](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@tylerpashigian](https://forum.ionicframework.com/u/tylerpashigian)\
**Post date:** [March 23, 2021, 1:16pm UTC](https://forum.ionicframework.com/t/ionic-5-unit-tests-with-routerlink/186138/3 "2021-03-23T13:16:14Z")

</div>

I had to add it to my `imports` array instead of `providers`, but this was the solution, thanks!
