react-boilerplate / react-boilerplate-cra-template

:fire: Setup Create React App with React Boilerplate. Highly scalable & Best DX & Performance Focused & Best practices.
https://react-boilerplate.github.io/react-boilerplate-cra-template/
MIT License
1.87k stars 393 forks source link

feat: ✨ fix i18n test #105

Closed antonsolokha96 closed 3 years ago

antonsolokha96 commented 3 years ago

if the component uses i18n, then an error occurs during testing:

    react-i18next:: You will need to pass in an i18next instance by using initReactI18next

      10 | 
      11 | export function Test(props: Props) {
    > 12 |   const { t } = useTranslation();
         |                 ^
      13 |   return <Div>{t('translations.someThing')}</Div>;
      14 | }

in the documentation i18n this is solved by mock (https://react.i18next.com/misc/testing).

jest.mock('react-i18next', () => ({
  useTranslation: () => {
    return {
      t: (str) => str,
      i18n: {
        changeLanguage: () => new Promise(() => {}),
      },
    };
  },
}));

My suggestion, add this solution to the component generation

coveralls commented 3 years ago

Pull Request Test Coverage Report for Build 478143191


Totals Coverage Status
Change from base Build 396972091: 0.0%
Covered Lines: 245
Relevant Lines: 245

💛 - Coveralls