title: Unit test i18Next - TypeError: Cannot read property 'init' of undefined
body: <p>My code is working fine but i got problem to setup unit test and test it. I got error when there is a code using the i18next library, could anyone give some advise?</p>
  
  <p>The below configuration is getting from <a href="https://react.i18next.com/misc/testing" rel="nofollow noreferrer">here</a></p>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'init' of undefined</p>
  
  <pre><code>   7 |  i18next
  &gt;  8 |   .init({
       |    ^
     9 |     interpolation: {
    10 |       escapeValue: false,
    11 |     },
  </code></pre>
  </blockquote>
  
  <p><strong>Helper.tsx</strong></p>
  
  <pre><code>export function validation(controlName: string){   
      var messages = require('src/translations/i18next');
      var requireMessage=messages.t('required');
      //omit irelevant code
    }
  </code></pre>
  
  <p><strong>Helper.test.tsx</strong></p>
  
  <pre><code>test('Validation',()=&gt;{
      expect(Helper.validation('My Name')).toBe('aaaaa');        
  })
  </code></pre>
  
  <p><strong>mock-setup.js</strong></p>
  
  <pre><code>jest.mock('i18next', () =&gt; ({
      use: () =&gt; {
        return {
          init: () =&gt; { }
        };
      },
      t: k =&gt; k
    }));
  </code></pre>
  
  <p><strong>jest.config.js</strong></p>
  
  <pre><code>module.exports = {
      verbose: true,
      'roots': [
        '&lt;rootDir&gt;/src'
      ],
      'transform': {            
        "^.+\\.(js)$": "&lt;rootDir&gt;/node_modules/babel-jest",
        "^.+\\.tsx?$": "ts-jest"
      },
      'testRegex': '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',    
      'moduleFileExtensions': [
        'ts',
        'tsx',
        'js',
        'jsx',
        'json',
        'node'
      ],
      'moduleNameMapper': {
        '^src/(.*)': '&lt;rootDir&gt;/src/$1',
        '^components/(.*)': '&lt;rootDir&gt;/src/components/$1'
      },
      'snapshotSerializers': ['enzyme-to-json/serializer'],
  
      'setupFiles': ['&lt;rootDir&gt;/src/jest/setupEnzyme.ts',
      '&lt;rootDir&gt;/src/jest/mock-setup.js', 
    ],
       'moduleDirectories': ['node_modules', 'src']
    }
  </code></pre>
  
  <p><strong>i18next.tsx</strong></p>
  
  <pre><code>import i18next from 'i18next';
  
  var common_en = require( "src/translations/en/common.json");
  var common_es = require( "src/translations/es/common.json");
  
  i18next
    .init({
      interpolation: {
        escapeValue: false,
      },
      lng: 'en', // 'en' | 'es'
      resources: {
        en: {translation: common_en},
        es: {translation: common_es},
      },
      debug: true,
    })
  
    export default i18next;
  </code></pre>
  
  <p><strong>tsconfig.json</strong></p>
  
  <pre><code>{
      "compilerOptions": {
          "lib": [ "es2015","dom" ],
        "target": "es5",
        "module": "commonjs",
        "esModuleInterop": true,
        "jsx": "react",   
        "sourceMap":  true, 
        "baseUrl": ".",
        "allowSyntheticDefaultImports": true,
          "paths": {
              "src/*": ["src/*"],
              "components/*": ["src/components/*"]            
          }
      } 
  }
  </code></pre>