Adding to i18n mocks

This commit is contained in:
Jeff Avallone 2018-02-15 17:35:12 -05:00
parent 79191c0fd7
commit 7a8a9836aa
5 changed files with 23 additions and 4 deletions

View File

@ -43,6 +43,7 @@
}, },
"collectCoverageFrom": [ "collectCoverageFrom": [
"src/**/*.js", "src/**/*.js",
"!src/i18n.js",
"!src/prerender.js", "!src/prerender.js",
"!src/setup/service-worker.js", "!src/setup/service-worker.js",
"!src/setup/jest.js", "!src/setup/jest.js",

20
src/__mocks__/i18n.js Normal file
View File

@ -0,0 +1,20 @@
import React from 'react';
import i18n from 'i18next';
import { I18nextProvider } from 'react-i18next';
const translate = txt => `translate(${ txt })`;
i18n.init({
fallbackLng: 'en',
fallbackNS: 'missing',
debug: false,
resources: {}
});
const I18nWrapper = ({ children }) => ( // eslint-disable-line react/prop-types
<I18nextProvider i18n={ i18n }>
{ React.cloneElement(React.Children.only(children), { t: translate }) }
</I18nextProvider>
);
export { translate, i18n, I18nWrapper };

View File

@ -1,2 +0,0 @@
const translate = txt => `translate(${ txt })`;
export default translate;

View File

@ -2,7 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { Form } from 'components/Form'; import { Form } from 'components/Form';
import translate from '__mocks__/translate'; import { translate, I18nWrapper } from '__mocks__/i18n';
const syntaxes = { const syntaxes = {
js: 'Javascript', js: 'Javascript',

View File

@ -5,7 +5,7 @@ import { shallow } from 'enzyme';
import Raven from 'raven-js'; import Raven from 'raven-js';
import { RavenError } from 'components/RavenError'; import { RavenError } from 'components/RavenError';
import translate from '__mocks__/translate'; import { translate } from '__mocks__/i18n';
const testError = { error: 'test error' }; const testError = { error: 'test error' };
const testDetails = { details: 'test details' }; const testDetails = { details: 'test details' };