0
我在這裏做錯了什麼?我有一段代碼,看起來是這樣的:爲什麼我的Q鏈接承諾拒絕行爲不符合我的期望?
function getUserList(requestingUserId){
return customerRepo.getCustomersAllowedByUser(requestingUserId)
.then(function(customers){
return userRepo.getUserList({customers: customers});
});
}
我的倉庫代碼掐滅這樣的:
customerDeferred = q.defer();
userDeferred = q.defer();
customerRepository.getCustomersAllowedByUser = sinon.stub().returns(customerDeferred.promise);
userRepository.getUsers = sinon.stub().returns(userDeferred.promise);
這一切工作正常時,這兩個承諾都解決了,並如預期,當我拒絕客戶承諾,但是當我解決客戶承諾並拒絕用戶許諾時,測試就會失敗。下面是測試:
it('should forward the rejection when userRepository rejects the promise', function(done){
var rejectionError = new Error("test");
var receivedError;
userServices.getUserList(1)
.then(null, function(error){
receivedError = error;
})
.fin(function(){
receivedError.should.equal(rejectionError);
done();
});
customerDeferred.resolve(customerList);
userDeferred.reject(rejectionError);
});
它是如何分解的? – loganfsmyth