New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stubbing sequential promise results #478
Comments
Can you point to the version of td.js that broke your usage? It looks like 3.14 was just typescript definition updates |
I have this problem after updating to the latest version 3.16.4 |
Could you tell me what version did work for you so we can bisect the change that's affecting your case? |
It worked at version 3.13.1, and it's not after I updated it to 3.16.4. Sorry for the unclear description. my old code at version 3.13.1 td.when(mockDynamo.update(putLockParams))
.thenReturn(Promise.reject({ code: conditionalCheckFailedException }), Promise.resolve({ Attributes: dbRecord })); my new code at version 3.16.4 in order to achieve the same sequence of stubbing results. It works but, I'd prefer if such workaround was not needed. let tryCount = 0;
td.when(mockDynamo.update(putLockParams))
.thenDo(() => {
tryCount++;
if(tryCount === 1) {
return Promise.reject({ code: conditionalCheckFailedException });
} else {
return Promise.resolve({ Attributes: dbRecord });
}
}); |
I've also come up on this issue and would like a resolution.
The introduction of Perhaps adding something like
to |
Since I don't use typescript, I'd really appreciate any help, @johnbotris |
@johnbotris, I like your idea. It can solve the problem and not confuse the type check between promise stub and regular stub. I'd love to help review and test your code after you make changes to it. |
description
I want to suggest an enhancement about
thenReject
andthenResolve
function. In the older version before 3.14. when I want to do a sequential promise return I can dothenReturn(Promise.resolve('value1'), Promise.reject(Error('error1')))
. However, now it forced me to usethenReject
andthenResolve
for stubbing promise, I can't actually achieve it easily with these two functions. As the code shows below. it will always return the last stubbing promise result. I was expecting that it will be the same sequence as I stubbing them.Right now I fix this problem by introducing a counter and
thenDo
function. Still, It's way messier than before. I hope it can be achieved by callingthenReject
andthenResolve
function in a more natural way.demo
env:
The text was updated successfully, but these errors were encountered: