title: How to configure Jest to work with Expo SDK 32
body: <p>I have an Expo app and was using SDK 28. My team decided we should update to the latest version, that meant updating React Native (Since the latest SDK uses RN 0.57) and Babel.</p>
  
  <p>When we updated our dependencies, and fixed our config files, Jest started to give us this error:</p>
  
  <pre class="lang-sh prettyprint-override"><code>TypeError: Cannot read property 'fetch' of undefined
  
        at node_modules/react-native/Libraries/vendor/core/whatwg-fetch.js:6:12
        at Object.&lt;anonymous&gt; (node_modules/react-native/Libraries/vendor/core/whatwg-fetch.js:486:3)
        at Object.&lt;anonymous&gt; (node_modules/jest-expo/src/setup.js:125:16)
  </code></pre>
  
  <p>After a few days debugging I found out this is related to <code>babel-jest</code>'s pre-processor not working correctly, even though I followed their installation <a href="https://github.com/facebook/jest/blob/master/README.md#using-babel" rel="nofollow noreferrer">docs</a>.</p>
  
  <p>I dug around some more and found out that there's a workaround in this <a href="https://github.com/expo/expo/issues/2595#issuecomment-440966998" rel="nofollow noreferrer">GitHub Issue thread</a>.</p>
  
  <p>Implementing the workaround, plus adding <a href="https://www.npmjs.com/package/babel-plugin-jest-hoist" rel="nofollow noreferrer">babel-hoist</a> to my <code>babel.config.js</code>, made so that the tests started running.</p>
  
  <p>However Jest's behavior is all wonky and the coverage data is not correct (it counts some lines as uncovered, even though we do have tests for them).</p>
  
  <p>I want to know how to configure Jest properly for compatibility with Expo SDK 32.</p>
  
  <p>These are the relevant config files (which are set to use the workaround mentioned previously).</p>
  
  <h3>package.json*</h3>
  
  <pre><code>"dependencies": {
      "@babel/preset-env": "^7.3.1",
      "@expo/vector-icons": "6.3.1",
      "expo": "^32.0.0",
      "prop-types": "15.6.2",
      "react": "16.5.0",
      "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
      "sentry-expo": "~1.9.0"
      ...
    },
    "devDependencies": {
      "@babel/core": "^7.2.2",
      "babel-eslint": "9.0.0",
      "babel-plugin-jest-hoist": "^24.0.0",
      "babel-preset-expo": "^5.0.0",
      "enzyme": "3.8.0",
      "enzyme-adapter-react-16": "^1.8.0",
      "jest-expo": "^32.0.0",
      "metro-react-native-babel-preset": "^0.51.1",
      "react-dom": "^16.5.1",
      ...
    },
  "jest": {
      "preset": "jest-expo",
      "transform": {
        "^.+\\.js$": "&lt;rootDir&gt;/jest.preprocessor.js"
      },
      "setupFiles": [
        "&lt;rootDir&gt;/src/jest.setup.js"
      ],
    ...
  }
  </code></pre>
  
  <p><strong>* Some dependecies were omitted.</strong></p>
  
  <h3>babel.config.js</h3>
  
  <pre><code>module.exports = {
    presets: [
      'babel-preset-expo',
      'module:metro-react-native-babel-preset',
      'module:react-native-dotenv',
      [
        '@babel/preset-env',
        {
          targets: {
            node: 'current',
          },
        },
      ],
    ],
    sourceMaps: true,
    plugins: [
      'jest-hoist',
      '@babel/transform-react-jsx-source',
    ],
  };
  </code></pre>