I have a component that is a simple disabled anchor with a router link
@Component({
template: `<a [routerLink]="target" disabled>click me</a>`,
})
class DisabledLinkComponent {
target = '/destination';
}
I want to test that the location does not change when clicking the anchor, using RouterTestingModule
.
@Component({ template: '' })
class FakeComponent {}
describe('DisabledLinkComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([{ path: 'destination', component: FakeComponent }])],
declarations: [DisabledLinkComponent, FakeComponent],
}).compileComponents();
}));
it('should not change location when clicked', () => {
const fixture = TestBed.createComponent(DisabledLinkComponent);
fixture.detectChanges();
fixture.nativeElement.querySelector('a').click();
expect(TestBed.get(Location).path()).not.toBe('/destination');
});
});
But the expectation fails. What is wrong in the way I test?