如何在业力茉莉花单元测试中验证模拟响应



我需要在服务的成功和错误状态之后验证响应。我的服务如下。

vm.onSupportFileDeleted = function (file) {
DocumentService.deleteDocument(file.fileId).then(function () {
var index = vm.supportingDocuments.indexOf(file);
vm.supportingDocuments.splice(index, 1);
vm.dzRemoveFile(file);
setSupportFileStatusA11yAlert('Document removed');
//advanced-options-link
angular.element('#advanced-options-link').trigger('focus');
}, function (msg) {
$log.error('Document not deleted - ' + JSON.stringify(msg));
showSupportingDocumentError('Unable to delete file');
setSupportFileStatusA11yAlert('Unable to remove document');
});
};

我需要验证索引,支持文档变量。 我创建了一个模拟,如下所示。

DocumentServiceMock = jasmine.createSpyObj('DocumentService', [
'deleteDocument'
]);

我该怎么做?

您已经创建了一个间谍对象,但没有创建模拟响应,您要做的是创建一个返回模拟值的间谍。

你想嘲笑你的承诺的回应,并对解决(然后(和拒绝(错误(做出断言(期望(。

这个线程中有示例 Angular 中基于单元测试承诺的代码

最新更新