-
Notifications
You must be signed in to change notification settings - Fork 3
/
testSetup.ts
108 lines (92 loc) · 2.29 KB
/
testSetup.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import '@testing-library/jest-dom';
import 'jest-canvas-mock';
import { resetAllWhenMocks } from 'jest-when';
import getIntlMessages from '~src/lib/getIntlMessages';
jest.mock('@silvermine/videojs-airplay');
jest.mock('@silvermine/videojs-chromecast');
jest.mock('next/image');
jest.mock('next/legacy/image');
jest.mock('video.js');
jest.mock('~lib/api/fetchApi');
jest.mock('~lib/getIntlMessages');
jest.mock('~lib/makeQueryClient');
jest.mock('~lib/swiper');
jest.mock('@segment/analytics-next', () => {
const originalModule = jest.requireActual('@segment/analytics-next');
return {
__esModule: true,
...originalModule,
AnalyticsBrowser: {
load: () => {
return {
track: jest.fn(),
page: jest.fn(),
reset: jest.fn(),
identify: jest.fn(),
};
},
},
};
});
interface CustomMatchers<R = unknown> {
toAppearBefore: (argument: HTMLElement) => R;
}
declare global {
/* eslint-disable */
// https://jestjs.io/docs/26.x/expect#expectextendmatchers
namespace jest {
interface Expect extends CustomMatchers {}
interface Matchers<R> extends CustomMatchers<R> {}
interface InverseAsymmetricMatchers extends CustomMatchers {}
}
/* eslint-enable */
}
expect.extend({
toAppearBefore(received: HTMLElement, argument: HTMLElement) {
const pass = !!(
received.compareDocumentPosition(argument) &
Node.DOCUMENT_POSITION_FOLLOWING
);
return {
message: () =>
pass
? `expected ${received} not to be before ${argument}`
: `expected ${received} to be before ${argument}`,
pass,
};
},
});
// WORKAROUND: https://github.com/keppelen/react-facebook-login/issues/217#issuecomment-375652793
beforeAll(() => {
const fbScript = document.createElement('script');
fbScript.id = 'facebook-jssdk';
document.body.appendChild(fbScript);
});
beforeEach(() => {
jest.clearAllMocks();
resetAllWhenMocks();
jest.mocked(getIntlMessages).mockResolvedValue({});
window.IntersectionObserver = jest.fn(
() =>
({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}) as any,
);
global.MutationObserver = jest.fn(
() =>
({
observe: jest.fn(),
disconnect: jest.fn(),
}) as any,
);
global.ResizeObserver = jest.fn(
() =>
({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}) as any,
);
});