Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jasmine的单元测试:点击一个按钮_Javascript_Angular_Unit Testing_Typescript_Jasmine - Fatal编程技术网

Javascript Jasmine的单元测试:点击一个按钮

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

我正在测试Angular应用程序中的一个组件:

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

有什么建议吗?