title: Can't get Jest to work together with react-navigation
body: <p>I've problems getting <a href="https://github.com/facebook/jest" rel="nofollow noreferrer">Jest</a> to work together with <a href="https://github.com/react-community/react-navigation" rel="nofollow noreferrer">react-navigation</a>. I've created a new project following the instructions in the <a href="https://reactnavigation.org/docs/intro/" rel="nofollow noreferrer">react-navigation guidelines</a>, and then added Jest and configured exactly as detailed below. The app runs fine, but when I run the tests I encounter the following error:</p>
  
  <pre><code>React caught an error thrown by NavigationContainer. You should fix this error in your code. Consider adding an error boundary to your tree to customize error handling behavior.
  
    TypeError: Cannot read property 'then' of undefined
  
    The error is located at: 
        in NavigationContainer (created by App)
        in App
  
    The error was thrown at: 
        at NavigationContainer.componentDidMount (/Users/gustav/kicksort/albert/albertReact1/node_modules/react-navigation/src/createNavigationContainer.js:189:2171)
        at commitLifeCycles (/Users/gustav/kicksort/albert/albertReact1/node_modules/react-test-renderer/lib/ReactFiberCommitWork.js:421:24),
        ...
        ...
  </code></pre>
  
  <p>Here are the relevant contents of my package.json file:</p>
  
  <pre><code>"dependencies": {
    "react": "16.0.0-alpha.6",
    "react-dom": "16.0.0-alpha.6",
    "react-native": "0.44.0",
    "react-navigation": "1.0.0-beta.9"
  },
  "devDependencies": {
    "babel-jest": "20.0.3",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
    "babel-preset-react-native": "^1.9.2",
    "enzyme": "2.8.2",
    "jest": "20.0.3",
    "jest-cli": "20.0.3",
    "jest-react-native": "18.0.0",
    "react-test-renderer": "16.0.0-alpha.6"
  },
  "jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-navigation)"
    ]
  }
  </code></pre>
  
  <p>Here's my .babelrc file:</p>
  
  <pre><code>{
    "presets": ["react-native"],
    "env": {
        "test": {
          "presets": ["react-native"],
          "plugins": ["transform-es2015-modules-commonjs"]
        }
     }
  }
  </code></pre>
  
  <p>And finally __mocks__/react-native.js:</p>
  
  <pre><code>const rn = require('react-native')
  jest.mock('Linking', () =&gt; {
    return {
      addEventListener: jest.fn(),
      removeEventListener: jest.fn(),
      openURL: jest.fn(),
      canOpenURL: jest.fn(),
      getInitialURL: jest.fn(),
    }
  })
  module.exports = rn;
  </code></pre>