我正在为以下代码编写茉莉花单元测试:
this.confirmationService.confirm({
message: 'Are you sure that you want to delete?',
accept: () => {
//some code to test
}
});
如何在对话框中伪造单击 Yes 来测试 accept() 函数中的代码?
我正在为以下代码编写茉莉花单元测试:
this.confirmationService.confirm({
message: 'Are you sure that you want to delete?',
accept: () => {
//some code to test
}
});
如何在对话框中伪造单击 Yes 来测试 accept() 函数中的代码?
在您的模板中:
<p-confirmDialog #confirmDialog header="Confirmation" icon="fa fa-question-circle" width="425"></p-confirmDialog>
在您的组件中:
@ViewChild('confirmDialog') confirmDialog: ConfirmDialog;
然后你就可以调用confirmDialog.accept()
.
您可以像这样创建间谍:
spyOn(confirmationService, 'confirm').and.callFake((params: Confirmation) => {
params.accept();
});