-
Notifications
You must be signed in to change notification settings - Fork 142
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
Awaiting a testdouble function always resolves #371
Comments
By default, You might try this: const lol = td.when(td.func()).thenReturn(new Promise())
await lol() ?? |
To answer Justin's implied question, from the MDN page on await:
That's why the default behavior of So if you want the result of the function to fulfill with a value other than
If you want it to reject:
But it sounds like you want it to return an un-resolved promise but have control over when it resolves later, so you would need something like:
|
Closing in favor of #372 |
Description
I'm trying to verify a function that calls several APIs but otherwise produces no output. I'm passing in the API client objects as parameters so they are easily replaceable with testdoubles.
Issue
When using
async/await
and awaiting any testdouble function, the function always returns undefined which makes the code continue. I would have expected the function to only ever resolve if I explicitly set that up withtd.when(…).thenResolve()
.Is this intentional behavior and is there already a proposed way to solve my use case? The only workaround I can think of right now is explicitly throwing an error when my testdouble is called with the wrong parameters.
Environment
node -v
output: 8.9.4npm -v
(oryarn --version
) output: 6.0.0npm ls testdouble
(oryarn list testdouble
) version:Code-fenced Examples
The text was updated successfully, but these errors were encountered: