title: Testing Promises in Jest
body: <p>I'm currently trying to test some Promise heavy functions in the codebase. This snippet also has the added joy of an event listener as well.</p>
  
  <p>How would I go about testing this?</p>
  
  <pre><code>const createImage = url =&gt;
    new Promise((resolve, reject) =&gt; {
      const image = new Image();
      image.addEventListener("load", () =&gt; resolve(image));
      image.addEventListener("error", error =&gt; reject(error));
      image.setAttribute("crossOrigin", "anonymous"); // needed to avoid cross-origin issues on CodeSandbox
      image.src = url;
    });
  
  export default createImage;
  </code></pre>