title: Mock a function called in a React component with jest
body: <p>I have a React component which calls an external API. I'm try to unit test this component, but I didn't understand how I can mock the function with jest and &quot;fake&quot; the result.</p>
  <p>Component:</p>
  <pre><code>import { getWeather } from '../../service/WeatherService'
  import {useState, useEffect} from 'react'
  
  export default function Weather() {
  
  ...
  
   useEffect(() =&gt; {
          getWeather().then((res) =&gt; { // function which calls the external API
  ...
  }
  
  </code></pre>