title: How can I mock the Geolocation API error function and !navigator.geolocation case in Jest?
body: <p>I use the Geolocation API in a React app and I want to test it in Jest. This is my Geolocation function in the app:</p>
  <pre><code>const getGeolocation = () =&gt; {
      const success = position =&gt; {
          const {latitude} = position.coords
          const {longitude} = position.coords
  
          // eslint-disable-next-line no-magic-numbers
          map.current.setView([latitude, longitude], 12)
      }
  
      const error = () =&gt; {
          // eslint-disable-next-line no-magic-numbers
          map.current.setView([46.378333, 13.836667], 12)
      }
  
      if (!navigator.geolocation) {
          // eslint-disable-next-line no-magic-numbers
          map.current.setView([46.378333, 13.836667], 12)
      } else {
          navigator.geolocation.getCurrentPosition(success, error)
      }
  }
  </code></pre>
  <p>I'm able to test the <code>success</code> function, but I can't reach the <code>error</code> function and I also was not able to mock the <code>!navigator.geolocation</code> case. This is my mock:</p>
  <pre><code>const mockGeolocation = {
      getCurrentPosition: jest.fn()
          .mockImplementationOnce(success =&gt; Promise.resolve(success({
              coords: {
                  latitude: 46.378333,
                  longitude: 13.836667,
              },
          }))),
      watchPosition: jest.fn(),
  }
  
  global.navigator.geolocation = mockGeolocation
  </code></pre>
  <p><strong>How can I mock the <code>error</code> function and the <code>!navigator.geolocation</code> case?</strong></p>