title: nodejs built-in assert with async/await function
body: <p>I use built-in nodejs <code>assert</code> module. I want to assert the result of the async function.</p>
  <pre class="lang-js prettyprint-override"><code>const assert = require('assert').strict;
  
  async function f() {
    return Promise.resolve(true);
  }
  
  (async () =&gt; {
    assert.equal(await f(), true);
    assert.equal(await f(), false);
  })();
  </code></pre>
  <p>If <code>expected</code> equals <code>actual</code>, it works. But if <code>expected</code> does not equal <code>actual</code>, I got <code>UnhandledPromiseRejectionWarning</code></p>
  <pre><code>$ node example.js
  (node:153779) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  
  true !== false
  
      at file:///home/matt/tmp/asyncawait/example.js:9:10
  (Use `node --trace-warnings ...` to show where the warning was created)
  (node:153779) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
  (node:153779) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>
  <p>Is using option <code>--unhandled-rejections=strict</code> right solution?</p>
  <pre><code>$ node -v
  v14.5.0
  </code></pre>
  <p>(updated 2020-07-19)</p>
  <p>If I set <code>--unhandled-rejections=strict</code>, I get expected output.</p>
  <pre><code>$ node --unhandled-rejections=strict example.js
  internal/process/promises.js:213
          triggerUncaughtException(err, true /* fromPromise */);
          ^
  
  AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
  
  true !== false
  
      at /home/matt/tmp/asyncawait/example.js:9:10 {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: true,
    expected: false,
    operator: 'strictEqual'
  }
  </code></pre>