I'm trying to test a component with some links, such as:
<a routerLink="/contact">Contact</a>
Also, I already tried looking into this question, but it didn't solved the problem.
When I try the solution proposed by that question (code below), I keep getting this error
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
declarations: [FooterComponent],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(FooterComponent);
component = fixture.componentInstance;
});
describe('...', () => {
it('should navigate to "/contact" when clicking on link', async(inject([Location], (location: Location) => {
fixture.debugElement.query(By.css('.menu')).children[1].nativeElement.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
console.log( location.path() );
});
})));
});
No provider for Location!
Then, if I tri to set providers: [Location] I get this error:
Failed: StaticInjectorError[LocationStrategy]:
StaticInjectorError[LocationStrategy]:
NullInjectorError: No provider for LocationStrategy!
I tried to spy on the Router, like this:
spyOn(router, 'navigate');
expect(router.navigate).toHaveBeenCalled();
But it fails the test with 'Never called'.
How can I solve this issue?