-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathsetupTest.js
More file actions
71 lines (58 loc) · 1.9 KB
/
setupTest.js
File metadata and controls
71 lines (58 loc) · 1.9 KB
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
import '@testing-library/jest-dom';
import { vi } from 'vitest';
import { setupIntersectionMocking } from 'react-intersection-observer/test-utils';
import i18next from 'i18next';
import createFetchMock from 'vitest-fetch-mock';
import en from './src/locales/en/translation.json';
// vitest doesn't set a default
window.origin = 'http://localhost';
vi.setConfig({ testTimeout: 10_000 });
const fetchMocker = createFetchMock(vi);
// changes default behavior of fetchMock to use the real 'fetch' implementation and not mock responses
beforeEach((context) => {
if (context.task.file.name.includes('/integration')) {
fetchMocker.disableMocks();
} else {
// sets globalThis.fetch and globalThis.fetchMock to our mocked version
fetchMocker.enableMocks();
}
});
/** */
class Path2D {
}
global.Path2D = Path2D;
setupIntersectionMocking(vi.fn);
i18next.init({
lng: 'en',
resources: {
en,
},
});
// --- Fullscreen mocking ---
const originalCreateElement = document.createElement;
/**
* Mock requestFullscreen globally for divs (used by FullScreenButton)
* This simulates an environment where requestFullscreen is supported
* This is the case for most browsers except iPhone Safari
*/
function mockRequestFullscreen() {
document.createElement = function createElementMock(tagName) {
const element = originalCreateElement.call(document, tagName);
if (tagName === 'div' && typeof element.requestFullscreen !== 'function') {
element.requestFullscreen = vi.fn(); // Simulate support
}
return element;
};
}
// Restore original createElement method
/**
*
*/
function disableMockRequestFullscreen() {
document.createElement = originalCreateElement;
}
// Mock fullscreen support by default
mockRequestFullscreen();
// Expose globally for tests to call when needed
global.__mockRequestFullscreen = mockRequestFullscreen;
global.__disableMockRequestFullscreen = disableMockRequestFullscreen;