You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I do not think this is a bug, more of a configuration issue/documentation issue, because clearly, I am doing something wrong
Language is not set during tests with vitest. In a dependency I import, this code exists:
functionuseI18N(){var_useTranslation=reactI18next.useTranslation(),t=_useTranslation.t,language=_useTranslation.i18n.language;if(language!=='nb'&&language!=='en'){throwError('Language must be either nb or en.');}returnt;}functionwithI18n(Component){returnfunctionWrappedComponent(props){vart=useI18N();return/*#__PURE__*/React__default["default"].createElement(Component,_extends({},props,{i18n: t}));};}
This code throws throw Error('Language must be either nb or en.'); when testing using vitest. It does not throw for building with vite nor with the previous test runner jest (with practically same config).
That code is wrapping a component that is consumed by several components up until the file I am testing, which is using this:
use(initReactI18next).init({lng: 'nb',fallbackLng: 'nb',resources: {nb: {translation: {
…
}},en: {translation: {
…
}}},interpolation: {escapeValue: false// not needed for react as it escapes by default}});exportdefaulti18n;
I've narrowed it down to react-i18next is not picking up language, i.e., that use(initReactI18next).init({…}) is not called, or something..
To Reproduce
I cannot produce a reproduction case due to the complexity of the internal (non public) dependencies, which I also think has something to do with this. As stated, I think this is a misconfiguration on my part, not a bug itself.
@adrai thanks for the suggestion. I've tried that with no avail sadly :/ Tried to include it in the test, in the test setup file, the renderWithI18NContext wrapper and in the component I am testing.
🐛 Bug Report
Note
I do not think this is a bug, more of a configuration issue/documentation issue, because clearly, I am doing something wrong
Language is not set during tests with
vitest
. In a dependency I import, this code exists:This code throws
throw Error('Language must be either nb or en.');
when testing usingvitest
. It does not throw for building withvite
nor with the previous test runnerjest
(with practically same config).That code is wrapping a component that is consumed by several components up until the file I am testing, which is using this:
With an import
i18n
that looks like this:Which is consumed like this:
I've narrowed it down to
react-i18next
is not picking up language, i.e., thatuse(initReactI18next).init({…})
is not called, or something..To Reproduce
I cannot produce a reproduction case due to the complexity of the internal (non public) dependencies, which I also think has something to do with this. As stated, I think this is a misconfiguration on my part, not a bug itself.
Expected behavior
That language is set.
Your Environment
The text was updated successfully, but these errors were encountered: