如何以角度测试http错误处理程序?

时间:2017-07-04 10:45:19

标签: angular unit-testing typescript

以下是代码示例:

this.paymentTypesService.updatePaymentTypesOrder('cashout', newOrder).subscribe(() => {
  this.notificationsService.success(
    'Success!',
    `Order change saved successfully`,
    { showProgressBar: true, pauseOnHover: true, clickToClose: true }
  );
}, () => {
  this.notificationsService.error(
    'Error',
    `Order change save failed`,
    { showProgressBar: true, pauseOnHover: true, clickToClose: true }
  );
});

paymentTypesService方法背后有简单的Http服务......在这种情况下我应该如何测试错误处理程序?

1 个答案:

答案 0 :(得分:0)

这样的事情应该有效:

spyOn(paymentTypesService, 'updatePaymentTypesOrder').and.returnValue(Observable.throw(new Error()))