-
-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: _i18next2.default.use is not a function #1017
Comments
do you have this only in the test suite or in general (running website) |
only in test suite when I try to mock i18next.... without mock it says i18next is not defined. Any help is appreciated. |
looks like the import does not be compatible with webpack try |
where exactly ? if you mean in test, how do I initialize it, like this:
of you meant something else ? |
somewhere you require or import i18next -> depending on your bundler it will not correctly do import i18next from 'i18next' -> as it won't work with default export correctly...typescript compiler and friends so you might exchange that with a named import |
ok, I only import it directly in locale file, and I setup options there. I switched it:
still same error. Any other idea ? |
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. |
Can I somehow mock this i18next.use(Locize), would it work like that ? Like I said , I only need to fix this in tests. |
for react -> but might help anyway: https://react.i18next.com/misc/testing.html |
you can mock away i18next completely i think -> just provide a function const i18next = {
use: () => {},
init: () => {},
t: key => key
} |
Thanks will try that out. ;) |
ok, when I mock it like this:
it throws similar but different error:
now it complains of init not being a function.... even though both use and init are mocked. Any suggestion would else could I try in this mock ? |
you will need to return this from your use function: const i18next = {
use: () => { return this; },
init: () => {},
t: key => key
} |
if I set :
it says: TypeError: Cannot read property 'init' of undefined The same error if I remove |
then try returning the constant itself |
in the end just make the function chain work ;) |
This partially worked to get another error msg:
https://stackoverflow.com/questions/48789110/how-to-mock-i18next-module-in-jest |
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 |
closing for now...feel free to reopen if still some issue |
i have same issue. but i'm using typescript and reactjs i follow the last setup from above comment, could you please advise? Thanks.
give me this error
|
Something wrong with imports in module. I've changed my code to |
Nothing wrong with imports...depends on the environment picking commonjs or es6 module... |
Thanks for comments, I got it working with:
|
I'm also getting same error : _i18next.default.addResourceBundle is not a function Although, My error was resolved via adding this two changes.
And woooo.. It works!! |
i am also getting same issue TypeError: _i18next.default.use is not a function
//mocking |
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 ?
The text was updated successfully, but these errors were encountered: