title: Jest - ReferenceError: __DEV__ is not defined (React Native)
body: <p>I am trying to get jest to work with a new <code>react-native</code> project. However, when I run <code>npm run test</code>, I get the following error <code>ReferenceError: __DEV__ is not defined</code>. I've looked through countless Github issues and Stack Overflow posts regarding this but none of the suggestions have worked in my case.</p>
  <p>Here is my <code>jest.config.js</code> file:</p>
  <pre><code>module.exports = {
      transformIgnorePatterns: [
         &quot;node_modules/(?!(react-native|react-native-button|react-native-video)/)&quot;
      ],  
      setupFiles: ['&lt;rootDir&gt;/__tests__/setup.json'],  
  }
  </code></pre>
  <p><code>package.json</code> (notice I added <strong>DEV</strong> = true inside &quot;jest&quot;)</p>
  <pre><code>{
    &quot;name&quot;: &quot;DigitalSignagePlayer&quot;,
    &quot;version&quot;: &quot;0.0.1&quot;,
    &quot;private&quot;: true,
    &quot;scripts&quot;: {
      &quot;android&quot;: &quot;react-native run-android&quot;,
      &quot;ios&quot;: &quot;react-native run-ios&quot;,
      &quot;start&quot;: &quot;react-native start&quot;,
      &quot;test&quot;: &quot;jest&quot;,
      &quot;lint&quot;: &quot;eslint .&quot;
    },
    &quot;dependencies&quot;: {
      &quot;@react-native-async-storage/async-storage&quot;: &quot;^1.15.5&quot;,
      &quot;axios&quot;: &quot;^0.21.1&quot;,
      &quot;react&quot;: &quot;^17.0.1&quot;,
      &quot;react-native&quot;: &quot;0.64.2&quot;,
      &quot;react-native-fs&quot;: &quot;^2.18.0&quot;,
      &quot;react-native-splash-screen&quot;: &quot;^3.2.0&quot;,
      &quot;react-native-video&quot;: &quot;^5.1.1&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;@babel/core&quot;: &quot;^7.14.5&quot;,
      &quot;@babel/preset-env&quot;: &quot;^7.14.7&quot;,
      &quot;@babel/runtime&quot;: &quot;^7.14.5&quot;,
      &quot;@react-native-community/eslint-config&quot;: &quot;^2.0.0&quot;,
      &quot;babel-jest&quot;: &quot;^27.0.2&quot;,
      &quot;eslint&quot;: &quot;^7.28.0&quot;,
      &quot;jest&quot;: &quot;^27.0.5&quot;,
      &quot;metro-react-native-babel-preset&quot;: &quot;^0.66.0&quot;,
      &quot;react-test-renderer&quot;: &quot;17.0.1&quot;
    },
    &quot;jest&quot;: {
      &quot;preset&quot;: &quot;react-native&quot;,
    }
  
  }
  </code></pre>
  <p><code>bable.config.js</code></p>
  <pre><code>module.exports = {
    presets: ['module:metro-react-native-babel-preset', '@babel/preset-env'],
    
  };
  </code></pre>
  <p><code>metro.config.js</code></p>
  <pre><code>/**
   * Metro configuration for React Native
   * https://github.com/facebook/react-native
   *
   * @format
   */
  
  module.exports = {
    transformer: {
      getTransformOptions: async () =&gt; ({
        transform: {
          experimentalImportSupport: false,
          inlineRequires: true,
        },
      }),
    },
  };
  </code></pre>
  <p>I have tried setting <code>globals.DEV = true</code> and <code>global.DEV = true</code> at the top of my test files. I have tried adding <code>setupFiles</code> to <code>jest.config.js</code> which loads a <code>setup.js</code> file that contains <code>global.DEV = true</code> too. I have tried updating <code>jest</code> also. My current version of <code>react-native</code> is:</p>
  <pre><code>react-native-cli: 2.0.1
  react-native: 0.64.2
  </code></pre>
  <p>I'm also using Metro, not Expo and I initially created the app with react-native-cli.</p>
  <p>UPDATE:</p>
  <p><code>setup.json</code></p>
  <pre><code>{
      &quot;globals&quot;: { &quot;__DEV__&quot;: true } 
  }
  </code></pre>
  <p>UPDATE 2:</p>
  <p>I changed <code>setup.json</code> to <code>setup.js</code> but I am still getting the same error:</p>
  <pre><code> global.__DEV__ = true
  </code></pre>