如何使用Jest对事件表单提交进行单元测试

时间:2020-05-11 14:25:05

标签: angular jestjs

我正在尝试使用开玩笑来测试此功能,但是没有运气,因为我不确定如何使用模拟的表单响应数据。

    public onFormSubmitHandler = ($event: MouseEvent): void => {
    this.formElem.nativeElement.handleSubmit().then(formResponse => {
                if (!(formResponse instanceof Error)) {
                    if (this.currentMode === "CREATE") {
                        this.createSource(formResponse);
                    } else if (this.currentMode === "UPDATE") {
                        this.updateSource(formResponse);
                    }
                }
            });
}

问题是,formResponse直到.then行才出现。我希望最终测试是

expect(this.createSource).toHaveBeenCalledWith(myMockFormResponse)

但是我不确定如何配置测试以使其通过。

0 个答案:

没有答案