-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.mock.js
60 lines (51 loc) · 1.95 KB
/
global.mock.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
const fetch = require('whatwg-fetch');
const { randomUUID } = require('node:crypto');
global.structuredClone = (v) => JSON.parse(JSON.stringify(v));
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
// The following module uses server-actions which causes tests to fail atm. Therefore, it can be mocked temporarily to resolve the issue.
// Github issue on next - https://github.com/vercel/next.js/issues/53065
jest.mock('@/components/explore-section/Literature/api.ts', () => ({
__esModule: true,
getGenerativeQA: jest.fn(),
}));
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
fetch: { value: fetch, writable: true },
})),
});
// mocking intersection observer, used in card view & explore article listing
const mockIntersectionObserver = jest.fn();
mockIntersectionObserver.mockReturnValue({
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});
window.IntersectionObserver = mockIntersectionObserver;
// Mocks for function from deepdash-es. The dependency is not resolved with jest, therefore the functions need to be mocked. (see - https://github.com/YuriGor/deepdash/issues/133)
export const findDeep = (flatTree, findFn) => ({
value: flatTree.find(findFn) ?? flatTree[0].items?.find(findFn),
});
export const reduceDeep = (someValue) => [someValue];
export const morphoviewer = () => null;
jest.mock(
'src/api/ontologies/index.ts',
() => jest.requireActual('__tests__/__utils__/Ontology').defaultOntologyMock
);
jest.mock('nuqs', () => ({
__esModule: true,
useQueryState: () => [null, jest.fn()],
}));
window.crypto.randomUUID = randomUUID;