/
AppLocalizationProvider.test.js
50 lines (38 loc) · 1.44 KB
/
AppLocalizationProvider.test.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
46
47
48
49
50
import React from 'react';
import sinon from 'sinon';
import { createReduxStore } from 'test/store';
import { shallowUntilTarget } from 'test/utils';
import { actions } from '..';
import AppLocalizationProvider, { AppLocalizationProviderBase } from './AppLocalizationProvider';
describe('<AppLocalizationProvider>', () => {
beforeAll(() => {
const getMock = sinon.stub(actions, 'get');
getMock.returns({type: 'whatever'});
});
afterEach(() => {
// Make sure tests do not pollute one another.
actions.get.resetHistory();
});
afterAll(() => {
actions.get.restore();
});
it('fetches a locale when the component mounts', () => {
const store = createReduxStore();
shallowUntilTarget(
<AppLocalizationProvider store={store} />,
AppLocalizationProviderBase
);
expect(actions.get.callCount).toEqual(1);
});
it('renders its children when locales are loaded', () => {
const store = createReduxStore();
store.dispatch(actions.receive('fr', { messages: [ 'hello' ] }));
const wrapper = shallowUntilTarget(
<AppLocalizationProvider store={store}>
<div id="content-test-AppLocalizationProvider" />
</AppLocalizationProvider>,
AppLocalizationProviderBase
);
expect(wrapper.find('#content-test-AppLocalizationProvider')).toHaveLength(1);
});
});