我正在尝试使用开玩笑来测试此功能,但是没有运气,因为我不确定如何使用模拟的表单响应数据。
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)
但是我不确定如何配置测试以使其通过。