Javascript Jasmine的单元测试:点击一个按钮
我正在测试Angular应用程序中的一个组件:Javascript Jasmine的单元测试:点击一个按钮,javascript,angular,unit-testing,typescript,jasmine,Javascript,Angular,Unit Testing,Typescript,Jasmine,我正在测试Angular应用程序中的一个组件: it('should not save empty alert after click on save button (async)', async(() => { fixture.detectChanges(); fixture.whenStable().then(() => { let Btn = fixture.debugElement.query(B
it('should not save empty alert after click on save button (async)', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
let Btn = fixture.debugElement.query(By.css('#btn-createAlert')).nativeElement;
comp.setCurrentAlert({});
expect(comp.getCurrentAlert().title).toBeUndefined();
expect(comp.getCurrentAlert().shops).toBeUndefined();
// click(saveBtn); ???
saveBtn.trigger('click');
fixture.detectChanges();
expect(saveSpy.calls.any()).toBe(false, 'alertService.saveAlert called');
expect(saveAlertShopsSpy.calls.any()).toBe(false, 'alertService.saveAlertShops called');
expect(loadAllSpy.calls.count()).toBe(1, 'alertService.getAllAlerts called only on ngOnInit');
});
}));
在我的测试用例中,如您所见,我得到了我的按钮的引用:
let Btn = fixture.debugElement.query(By.css('#btn-createAlert')).nativeElement;
为了不让我的测试用例工作,我需要点击它
不幸的是,我找不到任何本土的茉莉花工具来做这件事
以下建议不起作用:
saveBtn.trigger('click');
而且我不想导入任何外部库来执行此操作(既不是jquery,也不是jasmine matchers)
有什么建议吗?