/**
|
|
* Jest Setup File
|
|
* Configures test environment and global utilities
|
|
*/
|
|
|
|
// Mock window.matchMedia
|
|
Object.defineProperty(window, 'matchMedia', {
|
|
writable: true,
|
|
value: jest.fn().mockImplementation(query => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
addEventListener: jest.fn(),
|
|
removeEventListener: jest.fn(),
|
|
dispatchEvent: jest.fn(),
|
|
})),
|
|
});
|
|
|
|
// Mock localStorage
|
|
const localStorageMock = {
|
|
getItem: jest.fn(),
|
|
setItem: jest.fn(),
|
|
removeItem: jest.fn(),
|
|
clear: jest.fn(),
|
|
};
|
|
global.localStorage = localStorageMock;
|
|
|
|
// Mock sessionStorage
|
|
const sessionStorageMock = {
|
|
getItem: jest.fn(),
|
|
setItem: jest.fn(),
|
|
removeItem: jest.fn(),
|
|
clear: jest.fn(),
|
|
};
|
|
global.sessionStorage = sessionStorageMock;
|
|
|
|
// Mock console methods to reduce noise in tests
|
|
global.console = {
|
|
...console,
|
|
error: jest.fn(),
|
|
warn: jest.fn(),
|
|
};
|
|
|
|
// Add custom matchers
|
|
expect.extend({
|
|
toBeVisible(received) {
|
|
const pass = received.style.display !== 'none' &&
|
|
received.style.visibility !== 'hidden' &&
|
|
received.style.opacity !== '0';
|
|
|
|
return {
|
|
pass,
|
|
message: () => pass
|
|
? `expected element not to be visible`
|
|
: `expected element to be visible`,
|
|
};
|
|
},
|
|
});
|