Verify that an exception is thrown using Mocha / Chai and async/await : <p>I'm struggling to work out the best way to verify that a promise is rejected in a Mocha test while using async/await.</p>

<p>Here's an example that works, but I dislike that <code>should.be.rejectedWith</code> returns a promise that needs to be returned from the test function to be evaluated properly. Using async/await removes this requirement for testing values (as I do for the result of <code>wins()</code> below), and I feel that it is likely that I will forget the return statement at some point, in which case the test will always pass.</p>

<pre><code>// Always succeeds
function wins() {
  return new Promise(function(resolve, reject) {
    resolve('Winner');
  });
}

// Always fails with an error
function fails() {
  return new Promise(function(resolve, reject) {
    reject('Contrived Error');
  });
}

it('throws an error', async () =&gt; {
  let r = await wins();
  r.should.equal('Winner');

  return fails().should.be.rejectedWith('Contrived Error');
});
</code></pre>

<p>It feels like it should be possible to use the fact that async/await translates rejections to exceptions and combine that with Chai's should.throw, but I haven't been able to determine the correct syntax.</p>

<p>Ideally this would work, but does not seem to:</p>

<pre><code>it('throws an error', async () =&gt; {
  let r = await wins();
  r.should.equal('Winner');

  (await fails()).should.throw(Error);
});
</code></pre>
