So, when testing a component that uses the useTranslation hook, I get this warning:
react-i18next:: You will need pass in an i18next instance by using i18nextReactModule
It kinda says what I'm supposed to do, but I don't understand it. The setup of the jest suite contains the same i18n initialization code as the application (where everything works fine).
react-18next version: "10.1.1"
Reproduction
To me it looks like
Expected behaviour
For most tests this warning does not seem to have any repercussions. Is it actually needed?
OS (please complete the following information):
useTranslation needs an i18n instance -> so it warns about not having one.
either use i18next.use(initReactI18next) or the I18nextProvider to get "mock" down.
Details you should see in our tests in this repo and the JEST sample: https://github.com/i18next/react-i18next/tree/master/example/test-jest
Okay, I got round to set up the manual mock - it works fine, but I guess I'll have to watch out for breaking changes now.
@flq If you by any chance remember how you solved this, I would appreciate any additional info. I tried to make manual mock for react-i18next in __mocks__ folder adjacent to node_modules - exactly the same way as in the example project linked above, but my component still seems to use original implementation of useTranslation() when logged with useTranslation.toString() and as a result, I still see the warning.
I'm afraid this is rather a jest thing then - because for me, placing a file into __mocks__ worked. It is called react-i18next.js in my folder and it works...
Most helpful comment
useTranslationneeds an i18n instance -> so it warns about not having one.either use
i18next.use(initReactI18next)or theI18nextProviderto get "mock" down.Details you should see in our tests in this repo and the JEST sample: https://github.com/i18next/react-i18next/tree/master/example/test-jest