title: React Native Test with Jest impossible to mock Geolocation
body: <p>I tried to find a solution on the web and I found this <a href="https://stackoverflow.com/questions/43008925/how-to-mock-navigator-geolocation-in-a-react-jest-test">Stackoverflow answer</a>, I followed the instructions but I was blocked:</p>
  
  <pre><code>TypeError: Cannot set property 'geolocation' of undefined
  </code></pre>
  
  <p>So when I remove the solution my error is: </p>
  
  <pre><code>ReferenceError: navigator is not defined
  </code></pre>
  
  <p>My <code>package.json</code> looks like this: </p>
  
  <pre class="lang-json prettyprint-override"><code>  "dependencies": {
      "eslint-plugin-react-native": "^3.2.0",
      "prop-types": "^15.6.0",
      "react": "16.0.0",
      "react-native": "0.51.0",
    },
    "devDependencies": {
      "babel-core": "^6.26.0",
      "babel-eslint": "^8.1.2",
      "babel-jest": "^22.4.1",
      "babel-preset-react-native": "4.0.0",
      "enzyme": "^3.3.0",
      "enzyme-adapter-react-16": "^1.1.1",
      "eslint": "^4.14.0",
      "eslint-plugin-react": "^7.5.1",
      "jest": "^22.4.2",
      "jest-enzyme": "^6.0.0",
      "react-dom": "^16.2.0",
      "react-scripts": "^1.1.1",
      "react-test-renderer": "16.0.0-beta.5"
    },
    "jest": {
      "preset": "react-native",
      "moduleFileExtensions": [
        "js",
        "jsx"
      ],
      "moduleDirectories": [
        "node_modules"
      ],
      "transformIgnorePatterns": [
        "node_modules/(?!(jest-)?react-native|react-navigation)"
      ],
      "moduleNameMapper": {
        "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "&lt;rootDir&gt;/assetsTransformer.js",
        "\\.(css|less)$": "&lt;rootDir&gt;/assetsTransformer.js"
      },
      "verbose": true
    },
    "plugins": [
      "react",
      "react-native"
    ],
    "ecmaFeatures": {
      "jsx": true
    },
    "env": {
      "react-native/react-native": true
    }
  </code></pre>
  
  <p>And my test is just:</p>
  
  <pre class="lang-js prettyprint-override"><code>test('Map Component', () =&gt; {
    // create the snapshot
    const tree = renderer.create(&lt;Map/&gt;).toJSON();
    // test the snapshot
    expect(tree).toMatchSnapshot();
  });
  </code></pre>
  
  <p>The error is on this line, on the <code>navigator</code>: </p>
  
  <pre><code>navigator.geolocation.getCurrentPosition((position) =&gt; {
  </code></pre>
  
  <p>For the moment I am not testing my component with the navigator. I hope some of you have a solution, please.</p>