我想测试单击按钮后我的函数调用得很好。最好的方法是什么?
流量测试时出现此错误
错误:
[object ErrorEvent] thrown
我的测试规范:
describe('myComponent', () => {
beforeEach(() => {
spyOn(component, 'myFunction');
fixture.detectChanges();
});
it('Should test that myFunction is called when button clicked', () => {
let params = "VALUE";
let myBtn = fixture.debugElement.query(By.css('.item:nth-child(2) .delete'));
myBtn.triggerEventHandler('click', null);
expect(component.myFunction).toHaveBeenCalledWith(params);
});
});
答案 0 :(得分:0)
尝试更改:
myBtn.triggerEventHandler('click', null);
有:
myBtn.nativeElement.click();