我们在Angular应用程序中解决Promise的模式一直有效,直到Angular 1.6.0:
resource.get().$promise
.then(function (response) {
// do something with the response
}, function (error) {
// pass the error the the error service
return errorService.handleError(error);
});
以下是我们在Karma中触发错误的方式:
resourceMock.get = function () {
var deferred = $q.defer();
deferred.reject(error);
return { $promise: deferred.promise };
};
现在,随着1.6.0的更新,Angular在我们的单元测试(在Karma中)中为拒绝的承诺发出“可能未处理的拒绝”错误。但是我们在调用我们的错误服务的第二个函数中处理了拒绝。
Angular到底在这里寻找什么?它希望我们如何“处理”这个拒绝?