I just upgraded to Angular RC 5 and now all component that uses \'ROUTER_DIRECTIVES\' fails with \'Can\'t resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?)\' when I t
Was finally able to fix it, and it was as simple as this:
beforeEach(() => addProviders([
{
provide: Router,
useClass: class { navigate = jasmine.createSpy("navigate"); }
}]));
I did not have any luck with the above solutions. Instead, I followed the recommended approach in the official documentation: Testing Routed Components
First, create a stubbed router with whatever methods your component calls:
class RouterStub {
navigateByUrl(url: string) {
return url;
}
}
Then, when configuring your testing module you do the following:
TestBed.configureTestingModule({
declarations: [HeaderComponent],
providers: [
{provide: Router, useClass: RouterStub}
]
});