What am I doing wrong here? I have a piece of code that looks something like this:
function getUserList(requestingUserId){
return customerRepo.getCustomersAllowedByUser(requestingUserId)
.then(function(customers){
return userRepo.getUserList({customers: customers});
});
}
my repository code is stubbed out like this:
customerDeferred = q.defer();
userDeferred = q.defer();
customerRepository.getCustomersAllowedByUser = sinon.stub().returns(customerDeferred.promise);
userRepository.getUsers = sinon.stub().returns(userDeferred.promise);
It all works fine when both promises are resolved, and as expected when I reject the customer promise, however when I resolve the customer promise and reject the user promise the test breaks down. Here is the test:
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);
});