Skip to content

Commit 1a34961

Browse files
committed
Test nested namespaces
1 parent 6371a43 commit 1a34961

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/i18n/useI18n.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,15 @@ test('namespaced translations', async () => {
349349
</>;
350350
}
351351

352+
function Namespaced3() {
353+
const translate = useI18n();
354+
return <>
355+
<div data-testid="global3">{translate('global')}</div>
356+
<div data-testid="hello3">{translate('hello')}</div>
357+
<div data-testid="world3">{translate('world')}</div>
358+
</>;
359+
}
360+
352361
function Global() {
353362
const translate = useI18n();
354363
return <>
@@ -369,6 +378,12 @@ test('namespaced translations', async () => {
369378
<I18nProvider namespaces={['baz']}>
370379
<Namespaced2/>
371380
</I18nProvider>
381+
382+
<I18nProvider namespaces={['foo']}>
383+
<I18nProvider namespaces={['bar']}>
384+
<Namespaced3/>
385+
</I18nProvider>
386+
</I18nProvider>
372387
</>
373388
);
374389

@@ -378,6 +393,9 @@ test('namespaced translations', async () => {
378393
const globalNs2 = screen.getByTestId('global2');
379394
const helloNs2 = screen.getByTestId('hello2');
380395
const worldNs2 = screen.getByTestId('world2');
396+
const globalNs3 = screen.getByTestId('global3');
397+
const helloNs3 = screen.getByTestId('hello3');
398+
const worldNs3 = screen.getByTestId('world3');
381399
const global = screen.getByTestId('global');
382400
const hello = screen.getByTestId('hello');
383401
const world = screen.getByTestId('world');
@@ -389,6 +407,9 @@ test('namespaced translations', async () => {
389407
expect(globalNs2.textContent).toBe('something');
390408
expect(helloNs2.textContent).toBe('hello.');
391409
expect(worldNs2.textContent).toBe('world.');
410+
expect(globalNs3.textContent).toBe('something');
411+
expect(helloNs3.textContent).toBe('hello!');
412+
expect(worldNs3.textContent).toBe('world!');
392413
expect(global.textContent).toBe('something');
393414
expect(hello.textContent).toBe('hello...');
394415
expect(world.textContent).toBe('world...');
@@ -404,6 +425,9 @@ test('namespaced translations', async () => {
404425
expect(globalNs2.textContent).toBe('quelque chose');
405426
expect(helloNs2.textContent).toBe('bonjour.');
406427
expect(worldNs2.textContent).toBe('monde.');
428+
expect(globalNs3.textContent).toBe('quelque chose');
429+
expect(helloNs3.textContent).toBe('bonjour !');
430+
expect(worldNs3.textContent).toBe('monde !');
407431
expect(global.textContent).toBe('quelque chose');
408432
expect(hello.textContent).toBe('bonjour...');
409433
expect(world.textContent).toBe('monde...');

0 commit comments

Comments
 (0)