title: Why is jest.fn() not working after await?
body: <p>I use jest.fn()-functions for testing a node restapi server. I make extensive use of async/await and hit a problem I stripped down to this:</p>
  
  <blockquote>
    <p>test1.js</p>
  </blockquote>
  
  <pre><code>const test1 = async (res) =&gt; {
      res.status(500).send();  // Works here
  
      // Use a timer as an example, but should work with any promises
      await new Promise(resolve =&gt; setTimeout(resolve, 500));
  
      res.status(500).send();  // Doesn't work here
  }
  
  module.exports = test1;
  </code></pre>
  
  <blockquote>
    <p>test1.test.js</p>
  </blockquote>
  
  <pre><code>const jest = jest;
  
  import test1 from './test1';
  
  const res01 = {};
  
  let status;
  let send;
  
  beforeEach(() =&gt; {
      status = jest.fn();
      send = jest.fn();
  
      status.mockReturnValue({
          send
      });
  
      res01.status = status;
  });
  
  test('just testing ...', () =&gt; {
      test1(res01);
      expect(status).toHaveBeenCalledWith(500);
      expect(send).toHaveBeenCalledTimes(1);
  });
  </code></pre>
  
  <blockquote>
    <p>Jest-Settings</p>
  </blockquote>
  
  <pre><code>"jest": {
      "verbose": true,
      "transform": {
        "^.+\\.js$": "babel-jest"
      },
      "globals": {
        "NODE_ENV": "test"
      },
      "moduleFileExtensions": [
        "js"
      ],
      "moduleDirectories": [
        "node_modules"
      ],
      "moduleNameMapper": {
        "\\.(less|css|jpg|png)$": "&lt;rootDir&gt;/src/test/empty-module.js"
      }
    },
  </code></pre>
  
  <p>If res.status(500).send() if placed before the first use of an await, the test succeeds, when it's placed after the test fails. status is not called. Why?</p>