How to mock Picker and Picker.Item with jest in React-Native?
<p>I am trying to snapshot test this snippet of code:</p>

<pre><code>import React, { Component } from 'react';
import {
  Picker,
} from 'react-native';

export default class TestComponent extends Component {

  render() {
    return (
      &lt;Picker
        selectedValue={this.props.asset.type}
        onValueChange={this.props.onTypeChange}&gt;
        &lt;Picker.Item label="Type of asset" value="default" /&gt;
        &lt;Picker.Item label="Car" value="car" /&gt;
        &lt;Picker.Item label="Boat" value="boat" /&gt;
        &lt;Picker.Item label="Ship" value="ship" /&gt;
      &lt;/Picker&gt;
    );
  }
}
</code></pre>

<p>My test looks like this right now:</p>

<pre><code>import 'react-native';
import React from 'react';
import TestComponent from './TestComponent';

import renderer from 'react-test-renderer';

describe('TestComponent', () =&gt; {
  const asset = {
    type: 'car',
  }
  it('renders correctly', () =&gt; {
    const tree = renderer.create(
      &lt;TestComponent 
        asset={asset} /&gt;
    ).toJSON();
    expect(tree).toMatchSnapshot();
  });
})
</code></pre>

<p>My problem is that I get:</p>

<pre><code>TypeError: Cannot read property '_tag' of undefined
</code></pre>

<p>I think that I should mock it based on <a href="https://github.com/facebook/jest/issues/1384" rel="nofollow">this issue</a></p>

<p>I have tried adding simply:</p>

<pre><code>jest.mock('Picker', () =&gt; 'Picker')
</code></pre>

<p>But than it still throws an error because Picker.Item is still not mocked</p>

<pre><code>Invariant Violation: Element type is invalid: expected a string (for built-
in components) or a class/function (for composite components) 
but got: undefined. Check the render method of `TestComponent`.
</code></pre>

<p>Other variants I tried with no avail:</p>

<pre><code>jest.mock('Picker', () =&gt; {return {Item: 'Item'}});
----------------------------------------------------
class Picker{
  Item = 'PickerItem'
}
jest.mock('Picker', () =&gt; {
  return Picker;
});
</code></pre>