title: How do I mock react-i18next and i18n.js in jest?
body: <p>package.json</p>
  
  <pre><code>"moduleNameMapper": {
    "i18next": "&lt;rootDir&gt;/__mocks__/i18nextMock.js"
  }
  </code></pre>
  
  <p>i18n.js</p>
  
  <pre><code>import i18n from 'i18next'
  import XHR from 'i18next-xhr-backend'
  // import Cache from 'i18next-localstorage-cache'
  import LanguageDetector from 'i18next-browser-languagedetector'
  
  i18n
    .use(XHR)
    // .use(Cache)
    .use(LanguageDetector)
    .init({
      fallbackLng: 'en',
      // wait: true, // globally set to wait for loaded translations in translate hoc
      lowerCaseLng: true,
      load: 'languageOnly',
      // have a common namespace used around the full app
      ns: ['common'],
      defaultNS: 'common',
      debug: true,
  
      // cache: {
      //   enabled: true
      // },
  
      interpolation: {
        escapeValue: false, // not needed for react!!
        formatSeparator: ',',
        format: function (value, format, lng) {
          if (format === 'uppercase') return value.toUpperCase()
          return value
        }
      }
    })
  
  export default i18n
  </code></pre>
  
  <p>i18nextMock.js</p>
  
  <pre><code>/* global jest */
  const i18next = jest.genMockFromModule('react-i18next')
  i18next.t = (i) =&gt; i
  i18next.translate = (c) =&gt; (k) =&gt; k
  
  module.exports = i18next
  </code></pre>
  
  <p>For some reason the jest unit tests are not getting a component.</p>
  
  <p>Here is a unit test:</p>
  
  <pre><code>import React from 'react'
  import { Provider } from 'react-redux'
  import { MemoryRouter } from 'react-router-dom'
  import { mount } from 'enzyme'
  
  import { storeFake } from 'Base/core/storeFake'
  import Container from '../container'
  
  describe('MyContainer (Container) ', () =&gt; {
    let Component;
  
    beforeEach(() =&gt; {
      const store = storeFake({})
  
      const wrapper = mount(
        &lt;MemoryRouter&gt;
          &lt;Provider store={store}&gt;
            &lt;Container /&gt;
          &lt;/Provider&gt;
        &lt;/MemoryRouter&gt;
      )
  
      Component = wrapper.find(Container)
    });
  
    it('should render', () =&gt; {
      // Component is undefined here
      expect(Component.length).toBeTruthy()
    })
  })
  </code></pre>