Mocking navigator in RN for unit tests
<p>For my tests, Am using <code>mocha</code>, <code>enzyme</code>, <code>sinon</code> for stubing and <code>chai</code> for assertions, <code>mockery</code> for mocking modules.</p>

<p>Now whats the best possible mechanism to mock navigator for geolocation. I tried <code>rewire</code> from <code>https://github.com/jhnns/rewire</code> to inject my sinon stubed navigator. This will work for me, but just feels cumbersome to setup the stub.
I like <a href="https://github.com/2gis/mock-geolocation" rel="nofollow">https://github.com/2gis/mock-geolocation</a> as it feels more natural way of mocking. But unfortunately am not able to use it because it uses <code>window</code> variable. </p>

<p>I tried to use <code>mocha-jsdom</code> like </p>

<pre><code>import jsdom from 'mocha-jsdom';
jsdom();
const geolocate = require('mock-geolocation');
</code></pre>

<p>But I get an error like</p>

<pre><code>/..../node_modules/mock-geolocation/src/geolocate.js:225
})(window, navigator);
   ^

ReferenceError: window is not defined
    at Object.&lt;anonymous&gt; (/like

/..../node_modules/mock-geolocation/src/geolocate.js:225:4)
    at Module._compile (module.js:409:26)
</code></pre>

<p>I run my tests like this <code>mocha --require react-native-mock/mock --compilers js:babel-register --recursive</code> </p>