如何测试routerLink?
我尝试使用以下方法:
但是 href 变量为空。 我也尝试了 .nativeElement.href 但是返回了一个空字符串。
我尝试使用以下方法:
beforeEach(() => {
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
debugEl = fixture.debugElement;
element = debugEl.nativeElement;
fixture.detectChanges();
});
it('should have href with /login', () => {
fixture.detectChanges();
const href = debugEl.query(By.css('a')).nativeElement.getAttribute('href');
console.error(href) // give me null
//expect(expect(href)).toEqual('/login');
});
但是 href 变量为空。 我也尝试了 .nativeElement.href 但是返回了一个空字符串。