2017-07-04 72 views
0

下面是代碼樣本:如何在角度測試http錯誤處理程序?

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服務......我應該怎樣測試在這種情況下,錯誤處理程序?

回答

0

這樣的事情應該工作:

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

+0

任何運氣這麼遠? –