title: Test Promise with timeout Jest
body: <p>I have a simple code that resolves after 1 second:</p>
  <pre class="lang-js prettyprint-override"><code>const promiseWithTimeout = () =&gt; {
    return new Promise((resolve, reject) =&gt; {
      setTimeout(() =&gt; {
        resolve({id: 3});
      }, 1000);
    });
  };
  </code></pre>
  <p>I am trying to make a test using jest, however, using resolves or awaits makes it so the test passes even with the wrong expectation (unhandled rejection) .
  And If I try to make a failing test, it passes even if the expectation fails</p>
  <p>What I tried</p>
  <pre class="lang-js prettyprint-override"><code>it(&quot;Should return the right ID&quot;, ()=&gt;{
      expect.assertions(1);
      expect(promiseWithTimeout()).resolves.toEqual({id: 3});    // this one works fine
      jest.advanceTimersByTime(1000)
  
    })
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>it(&quot;Should return the right ID&quot;, ()=&gt;{
      expect.assertions(1);
      expect(promiseWithTimeout()).resolves.toEqual({id: 4});    // this PASSES , but shows 
      // UnhandledPromiseRejectionWarning: Error: expect(received).resolves.toEqual(expected) // deep equality
      jest.advanceTimersByTime(1000)
  
    })
  </code></pre>
  <p>I expected it to <strong>fail</strong> and show that the objects are different.</p>
  <p>I also tried using then instead, but still same problem</p>