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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling verify on rejected function fails test #483
Comments
My first reaction was to think "we throw a warning when verifying invocations that are also stubbed" and indeed, when changed to
It also prints the failure:
And the uncaught promise error:
Here's my REPLit fork to verify that. Am I missing something here? |
I guess I'm confused about the uncaught promise error. It seems to me like But the top level unhandled rejection seems to break my test suite Does that help? Can I provide any more info? 馃榾 |
I found that I can fix my tests by explicitly catching the error generated by this verify call. td.verify(
API.run('should fail').catch(err => null)
) This will still fail the test if |
Yes, this is happening to you as a side effect of stubbing what you're verifying. First the test stubs The real solution IMO is to address the td.js warning and not stub what you're also verifying, by instead adding a normal assertion that indirectly demands the stubbing be used as expected. This is how I would change it: td.replace(API, 'run')
td.when(API.run('should fail')).thenReject('fail')
async function test(): Promise<string> {
const value = await runSafely('should fail')
assert.strictEqual(value, 'fail')
return value
}
test()
.then(result => console.log('result', result))
.catch(err => console.log('error', err)) |
Hi again! Let me know if I can provide more info around this error or if I'm misunderstanding something about the lib 馃榾
Description
I would like to stub a call so that it models a promise rejection. Afterwards I would like to verify that function was called correctly.
Issue
Verifying the rejection causes my test to fail asynchronously. Since the stub was called as expected, I would expect my test to fail
Environment
node -v
output: v16.14.0npm -v
(oryarn --version
) output: 8.3.1npm ls testdouble
(oryarn list testdouble
) version: 3.16.4Runkit Notebook
https://replit.com/@JuanCaicedo1/TD-rejections#index.ts
Code-fenced Examples
The text was updated successfully, but these errors were encountered: