Test suite failed to run TypeError: Cannot read property 'default' of undefined : <p>I'm trying to setup Jest on my react-native project but it hasn't been playing nice with <a href="https://github.com/bugsnag/bugsnag-react-native" rel="noreferrer">bugsnag-react-native</a>.</p>

<p>With my current test configuration I'm seeing errors related to bugsnag's <code>leaveBreadcrumb</code> function seen below: </p>

<pre><code> FAIL  app/__tests__/NetworkReducer.test.js
  ● Test suite failed to run

    TypeError: Cannot read property 'default' of undefined

      at Object.&lt;anonymous&gt; (app/__tests__/NetworkReducer.test.js:10:20)
          at Generator.next (&lt;anonymous&gt;)
          at Promise (&lt;anonymous&gt;)
</code></pre>

<p>I have a helper file that instantiates bugsnag:</p>

<pre><code>helpers/bugSnag.js


//-------------------------------------------------------------------------------------------------
// Create a single instance of the bugsnag client so we don't have to duplicate our configuration
// anywhere.
//-------------------------------------------------------------------------------------------------
// https://docs.bugsnag.com/platforms/react-native/#basic-configuration

import { Client, Configuration } from 'bugsnag-react-native';
const config = new Configuration();
config.consoleBreadcrumbsEnabled = true;
config.notifyReleaseStages = ['testflight', 'production'];

const bugSnag = new Client(config);


export default bugSnag;
</code></pre>

<p>So in all my files I'm importing bugSnag from this helper file rather than declaring a new Client in each file, notably in my <code>NetworkReducer.js</code> where <code>bugSnag.leaveBreadcrumb('someData')</code> is causing me issues.</p>

<p>In my <code>NetworkReducer.test.js</code> I'm calling a mock:</p>

<pre><code> jest.mock(bugSnag, () =&gt; {
    return {
        leaveBreadcrumb: jest.fn()
    };
 });
</code></pre>

<p>where I'm also importing <code>bugSnag from path/to/helpers/bugSnag</code></p>

<p>If I comment out the mock, I get a different error message on each of my reducer types that have a <code>bugSnag.leaveBreadcrumb('someData')</code> as seen below:</p>

<pre><code>TypeError: _bugSnag2.default.leaveBreadcrumb is not a function

  at Object.network_prop_update (app/reducers/NetworkReducer.js:29:19)
  at app/reducers/createReducer.js:4:29
  at Object.&lt;anonymous&gt; (app/__tests__/NetworkReducer.test.js:80:29)
  at tryCallTwo (node_modules/promise/lib/core.js:45:5)
  at doResolve (node_modules/promise/lib/core.js:200:13)
  at new Promise (node_modules/promise/lib/core.js:66:3)
</code></pre>

<p>I thought I had a handle on this jest thing, and mocking,  but I guess I've been proven wrong. I've attached my Jest's <code>setup.js</code> for extra reference:</p>

<pre><code>    jest.mock('Linking', () =&gt; {
    return {
        addEventListener: jest.fn(),
        removeEventListener: jest.fn(),
        openURL: jest.fn(),
        canOpenURL: jest.fn(),
        getInitialURL: jest.fn(),
    };
});


jest.mock('PushNotificationIOS', () =&gt; {
    return {
        addEventListener: jest.fn(),
        requestPermissions: jest.fn(() =&gt; Promise.resolve()),
        getInitialNotification: jest.fn(() =&gt; Promise.resolve()),
    };
});


jest.mock('react-native-intercom', () =&gt; {
    return {
        registerIdentifiedUser: jest.genMockFn().mockReturnValue(Promise.resolve()),
        registerUnidentifiedUser: jest.genMockFn().mockReturnValue(Promise.resolve()),
        updateUser: jest.genMockFn().mockReturnValue(Promise.resolve()),
        reset: jest.genMockFn().mockReturnValue(Promise.resolve()),
        logEvent: jest.genMockFn().mockReturnValue(Promise.resolve()),
        handlePushMessage: jest.genMockFn().mockReturnValue(Promise.resolve()),
        displayMessenger: jest.genMockFn().mockReturnValue(Promise.resolve()),
        hideMessenger: jest.genMockFn().mockReturnValue(Promise.resolve()),
        displayMessageComposer: jest.genMockFn().mockReturnValue(Promise.resolve()),
        displayMessageComposerWithInitialMessage: jest.genMockFn().mockReturnValue(Promise.resolve()),
        displayConversationsList: jest.genMockFn().mockReturnValue(Promise.resolve()),
        getUnreadConversationCount: jest.genMockFn().mockReturnValue(Promise.resolve()),
        setLauncherVisibility: jest.genMockFn().mockReturnValue(Promise.resolve()),
        setInAppMessageVisibility: jest.genMockFn().mockReturnValue(Promise.resolve()),
        setupAPN: jest.genMockFn().mockReturnValue(Promise.resolve()),
        registerForPush: jest.genMockFn().mockReturnValue(Promise.resolve()),
        setUserHash: jest.genMockFn().mockReturnValue(Promise.resolve()),
        setBottomPadding: jest.genMockFn().mockReturnValue(Promise.resolve()),
        addEventListener: jest.fn(),
        removeEventListener: jest.fn()
    };
});


jest.mock('bugsnag-react-native', () =&gt; {
    return {
        leaveBreadcrumb: jest.fn(),
        Configuration: jest.fn(),
        Client: jest.fn()
    };
});
</code></pre>
