title: Jest async test times out if "expect" called within async function. Works sometimes. "Async callback was not invoked within timeout specified"
body: <p>I am using Jest with JS and trying to write a test around the X-ray JS library, a web scraping toolkit. The following is the test. This is using Jest 18.x and the latest x-ray js as of 02/20/2017.</p>
  
  <pre><code>const htmlResponse = require('../__mocks__/html_response'); // just contains {listingsPage: '&lt;html&gt;....&lt;/html&gt;';}
  
  describe('scraper', () =&gt; {
      it("should get David Nichols' latest study from valid HTML", (done) =&gt; {
          var listingsHtml = htmlResponse.listingsPage;
          const Xray = require('x-ray');
          const x = Xray();
          expect(x).not.toEqual(null);
          var parseHtml = x('#Repo tbody tr', { link: 'td:nth-child(1) a@href' })
          parseHtml(listingsHtml, (err, result) =&gt; {
              console.log(Object.keys(result));
              expect(result.link).toEqual('le test'); // commenting this out causes test to pass.
              done();
          });
  });
  </code></pre>
  
  <p>If I remove the <code>expect().toEqual</code> call inside the callback above the <code>done()</code> the test runs:</p>
  
  <pre><code> PASS  src/__tests__/scraper-test.js
  
  Test Suites: 1 passed, 1 total
  Tests:       1 passed, 1 total
  Snapshots:   0 total
  Time:        2.315s, estimated 6s
  Ran all test suites related to changed files.
  </code></pre>
  
  <p>with that line as-is, it times out. <code>result</code> is a simple object <code>{link: 'string'}</code> The test is making no network calls. I attempted updating the timeout value to 30 seconds with no luck.</p>
  
  <pre><code> FAIL  src/__tests__/scraper-test.js (5.787s)
  
    ● scraper › should get David Nichols' latest study from valid HTML
  
      Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
  
        at Timeout.callback [as _onTimeout] (node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/browser/Window.js:480:19)
        at ontimeout (timers.js:365:14)
        at tryOnTimeout (timers.js:237:5)
        at Timer.listOnTimeout (timers.js:207:5)
  
  Test Suites: 1 failed, 1 total
  Tests:       1 failed, 1 total
  Snapshots:   0 total
  Time:        6.641s
  Ran all test suites related to changed files.
  </code></pre>