ここで何が間違っていますか?次のようなコードがあります。
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);
});