title: How can I handle a promise in Jest?
body: <p>I'm getting an error right in this part of my code. <code>Received promise resolved instead of rejected</code> and I'm not sure how to handle this, can anyone help me?</p>
  <pre><code>it(&quot;should not create a media if the user doesn't exist&quot;, async () =&gt; {
      user.user= undefined;
      await usersRepository.save(user);
  
      await expect(
        createMedia.execute({
          userId: user.id,
          type: 'video',
          media: 'video-media',
          description: 'description',
        }),
      ).rejects.toBeInstanceOf(AppError);
    });
  </code></pre>
  <p>And:</p>
  <pre><code>expect(received).rejects.toThrow()
  
      Received promise resolved instead of rejected
      Resolved to value: {&quot;description&quot;: &quot;description&quot;, &quot;id&quot;: &quot;id number&quot;, &quot;media&quot;: &quot;video-media&quot;, &quot;userId&quot;: &quot;id user&quot;, &quot;type&quot;: &quot;video&quot;}
  </code></pre>