Node.js assert.throws with async functions (Promises)
<p>I want to check if an async function throws using <a href="https://nodejs.org/api/assert.html#assert_assert_throws_fn_error_message" rel="noreferrer"><code>assert.throws</code></a> from the native <code>assert</code> module.
I tried with</p>
<pre><code>const test = async () =&gt; await aPromise();
assert.throws(test); // AssertionError: Missing expected exception..
</code></pre>
<p>It (obviously?) doesn't work because the function exits before the Promise is resolved.
Yet I found <a href="https://stackoverflow.com/questions/19187111/assert-throws-on-asynchronous-method">this question</a> where the same thing is attained using callbacks.</p>
<p>Any suggestion?</p>
<p>(I'm transpiling to Node.js native generators using Babel.)</p>