当我将triggerEventHandler
与HTML按钮一起使用时,
const profileLink = fixture.debugElement.query(By.directive(RouterLinkWithHref));
profileLink.triggerEventHandler('click', null);
expect(routerSpy).toHaveBeenCalled();
测试成功,但是如果我将按钮更改为锚标记,则测试失败。我必须传递click事件,例如:
const profileLink = fixture.debugElement.query(By.directive(RouterLinkWithHref));
const leftclickevent = { button: 0 }; // left mouse button click event
profileLink.triggerEventHandler('click', leftclickevent);
expect(routerSpy).toHaveBeenCalled();
通过测试。为什么即使对于锚标记而不是按钮,我也必须传递点击?