Skip to content

Commit

Permalink
[#38] Fix i18n config mock for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Oct 27, 2021
1 parent 5a985b6 commit 5ecbe05
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
42 changes: 21 additions & 21 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ import LanguageDetector from 'i18next-browser-languagedetector';

export const supportedLanguages = ['en', 'fr'];

i18n
// load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
// learn more: https://github.com/i18next/i18next-http-backend
.use(Backend)
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(LanguageDetector)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
fallbackLng: 'en',
debug: false,
supportedLngs: supportedLanguages,
export const configureI18n = () => {
i18n
// load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales)
// learn more: https://github.com/i18next/i18next-http-backend
.use(Backend)
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(LanguageDetector)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
// for all options read: https://www.i18next.com/overview/configuration-options
.init({
fallbackLng: 'en',
debug: false,
supportedLngs: supportedLanguages,

interpolation: {
escapeValue: false // not needed for react as it escapes by default
}
});

export default i18n;
interpolation: {
escapeValue: false // not needed for react as it escapes by default
}
});
};
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import './index.scss';
import App from './App';
import reportWebVitals from './reportWebVitals';

import './i18n';
import {configureI18n} from './i18n';

configureI18n();

ReactDOM.render(
<React.StrictMode>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Object {
<li>
<a
class="language-switch__link "
data-test-id="language-switch-link-en"
href="#en"
>
language_switch.en
Expand All @@ -20,7 +19,6 @@ Object {
<li>
<a
class="language-switch__link "
data-test-id="language-switch-link-fr"
href="#fr"
>
language_switch.fr
Expand All @@ -36,7 +34,6 @@ Object {
<li>
<a
class="language-switch__link "
data-test-id="language-switch-link-en"
href="#en"
>
language_switch.en
Expand All @@ -45,7 +42,6 @@ Object {
<li>
<a
class="language-switch__link "
data-test-id="language-switch-link-fr"
href="#fr"
>
language_switch.fr
Expand Down
2 changes: 1 addition & 1 deletion src/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import App from '@src/App';
jest.mock('react-dom', () => ({ render: jest.fn() }));

// mock i18n import as we do not need translations setup for this test
jest.mock('@src/i18n', () => ({}));
jest.mock('@src/i18n', () => ({ configureI18n: jest.fn() }));

test('renders with App and root div', () => {
// Create and append to document body
Expand Down

1 comment on commit 5ecbe05

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 97.67% 42/43
🟢 Branches 87.5% 7/8
🟢 Functions 95% 19/20
🟢 Lines 97.56% 40/41

Test suite run success

27 tests passing in 9 suites.

Report generated by 🧪jest coverage report action from 5ecbe05

Please sign in to comment.