| 1 |
/** |
| 2 |
* Jest setup file for Sliderberg tests |
| 3 |
* |
| 4 |
* This file runs after Jest is initialized but before tests execute. |
| 5 |
* Use it to set up global test utilities and mocks. |
| 6 |
*/ |
| 7 |
|
| 8 |
import '@testing-library/jest-dom'; |
| 9 |
|
| 10 |
// Mock ResizeObserver which is not available in JSDOM |
| 11 |
class ResizeObserverMock { |
| 12 |
observe = jest.fn(); |
| 13 |
unobserve = jest.fn(); |
| 14 |
disconnect = jest.fn(); |
| 15 |
} |
| 16 |
|
| 17 |
global.ResizeObserver = ResizeObserverMock as unknown as typeof ResizeObserver; |
| 18 |
|
| 19 |
// Mock IntersectionObserver which is not available in JSDOM |
| 20 |
class IntersectionObserverMock { |
| 21 |
readonly root: Element | null = null; |
| 22 |
readonly rootMargin: string = ''; |
| 23 |
readonly thresholds: ReadonlyArray< number > = []; |
| 24 |
|
| 25 |
observe = jest.fn(); |
| 26 |
unobserve = jest.fn(); |
| 27 |
disconnect = jest.fn(); |
| 28 |
takeRecords = jest.fn( () => [] ); |
| 29 |
} |
| 30 |
|
| 31 |
global.IntersectionObserver = |
| 32 |
IntersectionObserverMock as unknown as typeof IntersectionObserver; |
| 33 |
|
| 34 |
// Mock matchMedia for responsive tests |
| 35 |
Object.defineProperty( window, 'matchMedia', { |
| 36 |
writable: true, |
| 37 |
value: jest.fn().mockImplementation( ( query: string ) => ( { |
| 38 |
matches: false, |
| 39 |
media: query, |
| 40 |
onchange: null, |
| 41 |
addListener: jest.fn(), // Deprecated |
| 42 |
removeListener: jest.fn(), // Deprecated |
| 43 |
addEventListener: jest.fn(), |
| 44 |
removeEventListener: jest.fn(), |
| 45 |
dispatchEvent: jest.fn(), |
| 46 |
} ) ), |
| 47 |
} ); |
| 48 |
|
| 49 |
// Suppress console errors during tests (optional, comment out for debugging) |
| 50 |
// const originalError = console.error; |
| 51 |
// beforeAll(() => { |
| 52 |
// console.error = (...args: unknown[]) => { |
| 53 |
// if (typeof args[0] === 'string' && args[0].includes('Warning:')) { |
| 54 |
// return; |
| 55 |
// } |
| 56 |
// originalError.call(console, ...args); |
| 57 |
// }; |
| 58 |
// }); |
| 59 |
// afterAll(() => { |
| 60 |
// console.error = originalError; |
| 61 |
// }); |
| 62 |
|