我在这里做错了什么?我有一段看起来像这样的代码:
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);
});