-
Notifications
You must be signed in to change notification settings - Fork 255
/
setupJest.js
49 lines (38 loc) · 1.13 KB
/
setupJest.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
/* eslint-disable import/no-extraneous-dependencies */
import fetchMock from 'jest-fetch-mock';
import sizeMe from 'react-sizeme';
import i18next from 'i18next';
import { setupIntersectionMocking } from 'react-intersection-observer/test-utils';
import en from './src/locales/en/translation.json';
jest.setTimeout(10000);
sizeMe.noPlaceholders = true;
const { TextEncoder } = require('util');
global.TextEncoder = TextEncoder;
// Setup Jest to mock fetch
fetchMock.enableMocks();
if (typeof Element !== 'undefined') Element.prototype.scrollTo = () => {};
setupIntersectionMocking(jest.fn);
/** */
function Path2D() {
}
global.Path2D = Path2D;
i18next.init({
lng: 'en',
resources: {
en,
},
});
jest.mock('react-i18next', () => ({
I18nextProvider: ({ children }) => children,
initReactI18next: {
init: jest.fn(),
type: '3rdParty',
},
// this mock makes sure any components using the translate HoC receive the t function as a prop
withTranslation: () => (Component) => {
Component.defaultProps = { // eslint-disable-line no-param-reassign
...Component.defaultProps, t: k => k,
};
return Component;
},
}));