I have nested promise calls structure as follow:
validateUser()
.then(() => {
getUserInformation()
.then((userInformation) => {
Promise.all([
getUserDebitAccounts(userInformation),
getUserCreditAccounts(userInformation)
])
.then(([drAcc, crAcc]) => {
//do something
})
})
})
.catch(error => {
callback(error);
});
First of all is there a way to simplify these nested calls? As you can see they are structure as per dependency. So this is a most logical way I came up.
Second can I use catch
at end to catch all the rejects on all above call. Do I have to add separate catch
for each calls?
Third I want to write a mocha test what level of Promise mocking I have to do for these methods some outline will be helpful.
Any suggestion?