-
Notifications
You must be signed in to change notification settings - Fork 255
/
setupJest.js
55 lines (43 loc) · 1.31 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
50
51
52
53
54
55
/* eslint-disable import/no-extraneous-dependencies */
import fetchMock from 'jest-fetch-mock';
import i18next from 'i18next';
import { setupIntersectionMocking } from 'react-intersection-observer/test-utils';
import en from './src/locales/en/translation.json';
jest.setTimeout(10000);
const { TextEncoder } = require('util');
global.TextEncoder = TextEncoder;
// Mock the browser's native ResizeObserver
global.ResizeObserver = jest.fn().mockImplementation(() => ({
disconnect: jest.fn(),
observe: jest.fn(),
unobserve: jest.fn(),
}));
// 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: () => (WrappedComponent) => {
/**
*
*/
const I18nAwareComponent = ({ t = (k => k), ...props }) => <WrappedComponent t={t} {...props} />; // eslint-disable-line react/prop-types
return I18nAwareComponent;
},
}));