/** * Jest Test Setup * Runs before each test file */ import '@testing-library/jest-dom'; // Mock localStorage const localStorageMock = { getItem: jest.fn(), setItem: jest.fn(), removeItem: jest.fn(), clear: jest.fn(), }; global.localStorage = localStorageMock; // Mock console methods in tests to reduce noise global.console = { ...console, error: jest.fn(), warn: jest.fn(), }; // Custom matchers expect.extend({ toBeValidChessPosition(received) { const isValid = received.row >= 0 && received.row < 8 && received.col >= 0 && received.col < 8; if (isValid) { return { message: () => `expected ${JSON.stringify(received)} not to be a valid chess position`, pass: true }; } else { return { message: () => `expected ${JSON.stringify(received)} to be a valid chess position`, pass: false }; } }, toBeValidFEN(received) { const fenRegex = /^([rnbqkpRNBQKP1-8]+\/){7}[rnbqkpRNBQKP1-8]+ [wb] [KQkq-]+ [a-h][1-8]|- \d+ \d+$/; const isValid = typeof received === 'string' && fenRegex.test(received); if (isValid) { return { message: () => `expected "${received}" not to be valid FEN`, pass: true }; } else { return { message: () => `expected "${received}" to be valid FEN`, pass: false }; } } }); // Reset mocks before each test beforeEach(() => { localStorageMock.getItem.mockClear(); localStorageMock.setItem.mockClear(); localStorageMock.removeItem.mockClear(); localStorageMock.clear.mockClear(); });