-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #714 from adrai/master
Added possibility to use useTranlation returning Array or Object
- Loading branch information
Showing
6 changed files
with
65 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
function defaultObjectUsage() { | ||
const { t, i18n } = useTranslation(); | ||
return ( | ||
<div> | ||
{t('key1')} {i18n.exists('key1')} | ||
</div> | ||
); | ||
} | ||
|
||
function alternateArrayUsage() { | ||
const [t, i18n] = useTranslation(); | ||
return ( | ||
<div> | ||
{t('key1')} {i18n.exists('key1')} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,42 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import i18n from './i18n'; | ||
import i18nInstance from './i18n'; | ||
import { useTranslation } from '../src/useTranslation'; | ||
|
||
jest.unmock('../src/useTranslation'); | ||
|
||
describe('useTranslation', () => { | ||
function TestComponent() { | ||
const [t, instance] = useTranslation('translation', { i18n }); | ||
describe('array', () => { | ||
function TestComponent() { | ||
const [t, instance] = useTranslation('translation', { i18nInstance }); | ||
|
||
expect(typeof t).toBe('function'); | ||
expect(instance).toBe(i18n); | ||
expect(typeof t).toBe('function'); | ||
expect(instance).toBe(i18nInstance); | ||
|
||
return <div>{t('key1')}</div>; | ||
} | ||
return <div>{t('key1')}</div>; | ||
} | ||
|
||
it('should render correct content', () => { | ||
const wrapper = mount(<TestComponent />, {}); | ||
// console.log(wrapper.debug()); | ||
expect(wrapper.contains(<div>test</div>)).toBe(true); | ||
it('should render correct content', () => { | ||
const wrapper = mount(<TestComponent />, {}); | ||
// console.log(wrapper.debug()); | ||
expect(wrapper.contains(<div>test</div>)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('object', () => { | ||
function TestComponent() { | ||
const { t, i18n } = useTranslation('translation', { i18n: i18nInstance }); | ||
|
||
expect(typeof t).toBe('function'); | ||
expect(i18nInstance).toBe(i18n); | ||
|
||
return <div>{t('key1')}</div>; | ||
} | ||
|
||
it('should render correct content', () => { | ||
const wrapper = mount(<TestComponent />, {}); | ||
// console.log(wrapper.debug()); | ||
expect(wrapper.contains(<div>test</div>)).toBe(true); | ||
}); | ||
}); | ||
}); |