forked from deriv-com/deriv-api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.ts
42 lines (37 loc) · 1.38 KB
/
jest.setup.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
import '@testing-library/jest-dom';
import 'jest-location-mock';
import 'jest-localstorage-mock';
// HINT: we need this mock for the tests with docusaurus components
window['docusaurus'] = {
prefetch: jest.fn(),
preload: jest.fn(),
};
// HINT: we need for radix-ui dropdown menu for account switcher, based on this https://stackoverflow.com/questions/68679993/referenceerror-resizeobserver-is-not-defined
// TODO: please remove this when we have the official account switcher from deriv-app
window.ResizeObserver =
window.ResizeObserver ||
jest.fn().mockImplementation(() => ({
disconnect: jest.fn(),
observe: jest.fn(),
unobserve: jest.fn(),
}));
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
Object.defineProperty(window, 'scrollTo', { value: jest.fn(), writable: true });
const originalConsoleWarn = console.warn;
console.warn = (...args) => {
// Filter out the specific warning about trackjs as we are not setting environment variables in the test environment
if (!args[0].includes('trackjs is not installed due to a missing token')) {
// Forward all other warnings to the original console.warn
originalConsoleWarn(...args);
}
};