Unhandled rejection error on "t.throws()" test of trivial async function
See original GitHub issueDescription
Unhandled rejection error on test of async function that throws
Test Source
import test from 'ava';
const f = async () => {
throw new Error();
};
test(async t => {
const error = await t.throws(async () => {
return await f();
});
t.is(error.message, '');
});
Error Message & Stack Trace
1 failed [08:28:15]
1 rejection
test › [anonymous]
/Users/scotty/workspace/fetch-nice/test/test.js:9
8:
9: const error = await t.throws(async () => {
10: return await f();
Test.<anonymous> (test/test.js:9:27)
step (test/test.js:9:191)
Test.<anonymous> (test/test.js:9:99)
Test.__dirname [as fn] (test/test.js:7:1)
Unhandled Rejection
Error
test/test.js:4:11
Generator.next (<anonymous>)
step (test/test.js:9:191)
test/test.js:9:437
test/test.js:9:99
f (test/test.js:3:7)
test/test.js:10:22
Generator.next (<anonymous>)
step (test/test.js:9:191)
test/test.js:9:437
test/test.js:9:99
_tryBlock (node_modules/core-assert/index.js:311:5)
_throws (node_modules/core-assert/index.js:330:12)
Function.assert.throws (node_modules/core-assert/index.js:360:3)
Test.<anonymous> (test/test.js:9:27)
Generator.next (<anonymous>)
step (test/test.js:9:191)
test/test.js:9:437
Test.<anonymous> (test/test.js:9:99)
Test.__dirname [as fn] (test/test.js:7:1)
Config
{
"ava": {
"require": [
"babel-register",
"babel-polyfill"
]
}
}
Command-Line Arguments
ava -w
Environment
Node.js v7.6.0 darwin 15.6.0 ava 0.19.1 npm 4.1.2
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:9 (6 by maintainers)
Top Results From Across the Web
How can I use ava's t.throws to test the error message of a ...
Try calling the functions and passing whatever is returned to t.throws() . eg. : test('throws works with functions that return promises (this fails)',...
Read more >JavaScript Promises: All you need to know - Medium
A promise is an object that represents eventual completion or failure of an asynchronous operation and its subsequent result value. Dive deeper ...
Read more >Unit testing with Jest - Naftali Murgor
A quick intro to unit testing Nodejs applications. ... calls with try...catch if using async/await to avoid unhandled promise rejection.
Read more >How to Interact With a Database Using Promises in Node.js
If an error is thrown and goes unhandled, then the promise will be rejected and the error will be passed to the next...
Read more >JavaScript: Don't throw exceptions from async functions
When your function returns a promise ("async function"), try not throw synchronous exceptions when encountering fatal errors. So avoid this:
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
👍
This was fixed in #1650.