i18next: TypeError: _i18next2.default.use is not a function

Hello,

I’m trying to setup testing suite with jest+ vue-test-utils or karma+jasmine+vue-test-utils (both throw same errors).

Is this problem with library or not ? Any idea how this can be solved ?

 TypeError: _i18next2.default.use is not a function

      34 |
      35 | i18next
    > 36 |      .use(Locize)
      37 |      .init(i18nextOptions);
      38 |
      39 | export default new VueI18Next(i18next);

      at Object.<anonymous> (src/app/locale/i18n.js:36:1)
      at Object.<anonymous> (src/app/store/modules/account/mutations.js:6:13)
      at Object.<anonymous> (src/app/store/modules/account/index.js:7:18)
      at Object.<anonymous> (src/app/store/index.js:17:16)      at src/app/pages/home/index/index.vue:24:14
      at Object.<anonymous> (src/app/pages/home/index/index.vue:230:3)
      at Object.<anonymous> (test/unit/home.spec.js:10:14)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

seems the vue-i18next depends on the event emitter build in…you will have to mock that too

evetual a good idea to ask there @panter/vue-i18next what functions on i18next are needed to have a complete mock

I’m also getting same error : _i18next.default.addResourceBundle is not a function

Although, My error was resolved via adding this two changes.

  1. create mocks folder in your /src directory
  2. then create new flle named “react-i18next.js”
  3. then simply pase the code as instructed here : https://github.com/i18next/react-i18next/blob/master/example/v9.x.x/test-jest/__mocks__/react-i18next.js
  4. then go into your */.test.js file
  5. then add mock function like below jest.mock("i18next", () => ({ addResourceBundle: jest.fn(), }));

And woooo… It works!!

you can mock away i18next completely i think -> just provide a function t on it returning first prop and noops for the rest

const i18next = {
  use: () => {},
  init: () => {},
  t: key => key
}

not really…just do a console.log of i18next…seems to be import related…

// import i18next from 'i18next';
import { default as i18next } from 'i18next';
console.log(i18next); // -> must be undefined i guess
import VueI18Next from '@panter/vue-i18next';

not had such an issue ever…hard to help without having options to debug…but must be related to import.