forked from ProjectMirador/mirador
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupJest.js
68 lines (54 loc) · 1.6 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
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-disable import/no-extraneous-dependencies */
import fetchMock from 'jest-fetch-mock';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
jest.setTimeout(10000);
const { TextEncoder } = require('util');
global.TextEncoder = TextEncoder;
// Setup Jest to mock fetch
fetchMock.enableMocks();
/* eslint-disable require-jsdoc, class-methods-use-this */
class IntersectionObserverPolyfill {
constructor(callback, options) {
this.callback = callback;
this.elements = [];
IntersectionObserverPolyfill.register(this);
}
observe(el) {
this.elements.push(el);
}
unobserve() {
}
disconnect() {
}
static register(obj) {
this.observers = this.observers || [];
this.observers.push(obj);
}
static triggerAll(attr = { intersectionRatio: 1, isIntersecting: true }) {
this.observers.forEach((obs) => {
obs.callback(obs.elements.map(el => ({ ...attr, target: el })));
});
}
}
/* eslint-enable require-jsdoc, class-methods-use-this */
global.IntersectionObserver = IntersectionObserverPolyfill;
/** */
function Path2D() {
}
global.Path2D = Path2D;
Enzyme.configure({ adapter: new Adapter() });
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;
},
}));