title: Testing a React Native component's function that is using try/catch and calls Image.getSize
body: <p>I am trying to write a jest test for the following React Native function that is defined inside a component:</p>
  
  <p>The function gets a data object that has two fields: <code>url</code> and <code>image</code>, and, based on their values, sets the component's state. </p>
  
  <p>Any suggestion how to test the function when data.image is not null, but a URI of an image? (e.g. <code>http://a.com/a.png</code>)</p>
  
  <pre><code>getArticleDetails (data) {
    const { url, image } = data
  
    if (!image) {
      this.setState({ url, image })
    } else {
      try {
        Image.getSize(image, (width, height) =&gt; {
          if (width &gt; 2000 || height &gt; 2000) {
            image = null
          }
          this.setState({ url, image })
        }, (error) =&gt; {
          image = null
          this.setState({ url, image, title, description })
        })
      } catch (e) {
        image = null
        this.setState({ url, image })
      }
    }
  }
  </code></pre>