title: Testing async/await method. Exception not being caught by Jest in unit test
body: <p>I'm attempting to test some code that uses <code>await</code> and <code>async</code> using Jest. The problem I'm having is an exception is thrown, but Jest doesn't seem to catch it.</p>
  
  <p>For example, here is <code>run</code> method that checks to see if <code>session.url</code> is present. If not, an exception is thrown:</p>
  
  <pre><code>const args = require('args');
  const fs = require('fs');
  const { promisify } = require('util');
  
  const readFile = promisify(fs.readFile);
  
  // Loads JSON configuration file
  module.exports.loadConfigFile = async (filename) =&gt; {
    const contents = await readFile(filename, 'utf8');
    return JSON.parse(contents);
  };
  
  // Prepare session ensuring command line flags override config
  module.exports.prepareSession = async (flags) =&gt; {
    if(!flags.config) return flags;
    const config = await this.loadConfigFile(flags.config);
    return {...config, ...flags};
  };
  
  // Runs the race application
  module.exports.run = async (flags = {}) =&gt; { 
    const session = await this.prepareSession(flags);
    if(!session.url) throw new Error('A valid URL is required');
  };
  </code></pre>
  
  <p>Here I test to see if an exception is thrown:</p>
  
  <pre><code>describe('Race Module', () =&gt; {
    test('Throws exception if no URL is provided', async () =&gt; {
      const runner = await race.run();
      expect(runner).toThrowError();
    });
  
    ...
  </code></pre>
  
  <p>The test runs and it appears an exception is thrown but jest hasn't caught it and it doesn't pass:</p>
  
  <pre><code>Race Module
      ✕ Throws exception if no URL is provided (3ms)
  
  ● Race Module › Throws exception if no URL is provided
  
  A valid URL is required
  
    at Object.&lt;anonymous&gt;.module.exports.run (src/race.js:23:27)
        at &lt;anonymous&gt;
  </code></pre>
  
  <p>Any ideas where I'm going wrong?</p>
  
  <p>My initial thought was to chain <code>catch(() =&gt; {})</code> to <code>race.run()</code> in the test but I am not entirely sure how I would test that. That might not even be the problem.</p>