Skip to content

Commit

Permalink
Fix defaults (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca authored Jan 8, 2020
1 parent fa76ce9 commit b79f0c8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5,785 deletions.
37 changes: 37 additions & 0 deletions __tests__/useTranslation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,43 @@ describe('useTranslation', () => {
afterEach(cleanup)

describe('fallbacks', () => {
test('should return an empty string if t(undefined)', () => {
const Inner = () => {
const { t } = useTranslation()
const test = t(undefined)
return (
<>
{test} | {typeof test}
</>
)
}

const expected = ' | string'

const { container } = render(
<I18nProvider lang="en" namespaces={{}}>
<Inner />
</I18nProvider>
)
expect(container.textContent).toBe(expected)
})

test('should return the key as fallback using wrong the nested translations', () => {
const i18nKey = 'ns:grandfather.parent'
const expected = 'ns:grandfather.parent'
const nested = {
grandfather: {
parent: {
child: 'I am the child',
},
},
}
const { container } = render(
<TestEnglish namespaces={{ ns: nested }} i18nKey={i18nKey} />
)
expect(container.textContent).toContain(expected)
})

test('should return the key as fallback WITH PROVIDER', () => {
const Inner = () => {
const { t } = useTranslation()
Expand Down
Loading

0 comments on commit b79f0c8

Please sign in to comment.