title: Why is the Promise reject() in my jest.mock going to a then() rather than a catch()?
body: <p>I have two files, <code>getItemInfo.js</code> to make API calls and <code>getItemInfo.test.js</code> which is the respective Jest test file. </p>
  
  <p>On the test file, I am mocking the http calling triggered by node module <code>request-promise</code>.</p>
  
  <p>The question is on the second code block, surrounded by <code>*********</code>'s. 
  Basically why is the <code>reject()</code> error still going to a <code>then()</code> block in the second unit test?</p>
  
  <pre><code>// getItemInfo.js
  
  const rp = require('request-promise');
  
  const getItemInfo = (id) =&gt; {
      const root = 'https://jsonplaceholder.typicode.com/posts/';
      const requestOptions = {
          uri: `${root}/${id}`,
          method: 'GET',
          json: true
      }
  
      return rp(requestOptions)
      .then((result) =&gt; {
          return result;
      })
      .catch((err) =&gt; {
          return err;
      });
  };
  
  module.exports = {
      getItemInfo: getItemInfo
  };
  </code></pre>
  
  <p>And here is my Jest unit test file.</p>
  
  <pre><code>// getItemInfo.test.js
  const ItemService = require('./getItemInfo');
  
  jest.mock('request-promise', () =&gt; (options) =&gt; {
      const id = Number.parseInt(options.uri.substring(options.uri.lastIndexOf('/') + 1));
  
      return new Promise((resolve, reject) =&gt; {
          if (id === 12) {
              return resolve({
                  id: id,
                  userId: 1,
                  title: '',
                  body: ''
              });
          } else {
              return reject('something went wrong'); // &lt;-- HERE IS THE REJECT
          }
      })
  });
  
  describe('getItemInfo', () =&gt; {
      it('can pass', done =&gt; {
          const TEST_ID = 12
          ItemService.getItemInfo(TEST_ID).then((result) =&gt; {
              console.log('result:',result);
              expect(result.id).toBe(TEST_ID);
              expect(result.userId).toBeDefined();
              expect(result.title).toBeDefined();
              expect(result.body).toBeDefined();
              done();
          });
      });
  
      it('can fail', (done) =&gt; {
          const TEST_ID = 13;
          ItemService.getItemInfo(TEST_ID)
          .catch((err) =&gt; {
              // *************
              // This "catch" block never runs
              // even if the jest.mock above Promise.rejects
              // Why is that???
              // *************
              console.log('catch():', err);
              done();
          })
          .then((result) =&gt; {
              // this block runs instead.
              // and it returns "then: something went wrong"
              console.log('then():', result);
              done();
          });
      });
  });
  </code></pre>
  
  <p>This is the unit test's output. The command is simply <code>jest</code>. The last line should be run from the <code>catch()</code> statement, not the <code>then()</code>:</p>
  
  <pre><code>PASS  ./getItemInfo.test.js
   getItemInfo
     ✓ can pass (9ms)
     ✓ can fail (1ms)
  
  Test Suites: 1 passed, 1 total
  Tests:       2 passed, 2 total
  Snapshots:   0 total
  Time:        0.703s, estimated 1s
  Ran all test suites.
  ----------------|----------|----------|----------|----------|----------------|
  File            |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
  ----------------|----------|----------|----------|----------|----------------|
  All files       |      100 |      100 |      100 |      100 |                |
  getItemInfo.js |      100 |      100 |      100 |      100 |                |
  ----------------|----------|----------|----------|----------|----------------|
   console.log getItemInfo.test.js:25
     result: { id: 12, userId: 1, title: '', body: '' }
  
   console.log getItemInfo.test.js:48
     then(): something went wrong
  </code></pre>
  
  <p>What am I doing wrong?</p>