How to test a React Native component that imports a custom native module with Jest?
<p>Here is a simple component that I am trying to test using React Native 0.39 and Jest 18:</p>

<pre><code>// index.ios.js

import React, { Component } from 'react';
import { AppRegistry, NativeModules, View } from 'react-native';

export default class TestProject extends Component {
  componentDidMount() {
    NativeModules.TestModule.test();
  }

  render() {
    return &lt;View style={{ flex: 1 }} /&gt;;
  }
}

AppRegistry.registerComponent('TestProject', () =&gt; TestProject);
</code></pre>

<p>Here is TestModule and its <code>test</code> method:</p>

<pre><code>// ios/TestProject/TestModule.m

#import "TestModule.h"

@implementation TestModule

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(test){
  NSLog(@"This is a test");
}

@end
</code></pre>

<p>The following test fails with the error <code>TypeError: Cannot read property 'test' of undefined</code>:</p>

<pre><code>// __tests__/index.ios.js

import 'react-native';
import renderer from 'react-test-renderer';
import React from 'react';
import Index from '../index.ios.js';

it('renders correctly', () =&gt; {
  const tree = renderer.create(
    &lt;Index /&gt;
  );
});
</code></pre>

<p>I have read the Jest docs on how to <a href="https://facebook.github.io/jest/docs/tutorial-react-native.html#mock-native-modules-using-jestmock" rel="noreferrer">Mock native modules using jest.mock</a>, but am still unclear as to how to extend Jest's mock of NativeModules to include my TestModule class above.</p>