forked from i18next/react-i18next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseSSR.spec.js
45 lines (40 loc) · 1 KB
/
useSSR.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { renderHook } from '@testing-library/react-hooks';
import i18n from './i18n';
import { setI18n } from '../src/context';
import { useSSR } from '../src/useSSR';
jest.unmock('../src/useSSR');
describe('useSSR', () => {
const mockI18n = {
language: 'en',
languages: ['en'],
options: {
ns: [],
defaultNS: 'defaultNS',
nsMode: 'fallback',
},
services: {
resourceStore: {
data: {},
},
backendConnector: {},
},
isInitialized: true,
changeLanguage: (lng) => {
mockI18n.language = lng;
},
getFixedT: () => (message) => message,
hasResourceBundle: (lng, ns) => ns === 'alreadyLoadedNS',
loadNamespaces: () => {},
};
beforeAll(() => {
setI18n(mockI18n);
});
afterAll(() => {
setI18n(i18n);
});
it('should set values', () => {
renderHook(() => useSSR({ foo: 'bar' }, 'de'));
expect(mockI18n.language).toBe('de');
expect(mockI18n.services.resourceStore.data).toEqual({ foo: 'bar' });
});
});