56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
|
// allows you to do things like:
|
|
// expect(element).toHaveTextContent(/react/i)
|
|
// learn more: https://github.com/testing-library/jest-dom
|
|
import '@testing-library/jest-dom';
|
|
|
|
// Mock window.location for tests that use navigation
|
|
const mockLocation = {
|
|
...window.location,
|
|
href: 'http://localhost:3000',
|
|
pathname: '/',
|
|
assign: jest.fn(),
|
|
replace: jest.fn(),
|
|
reload: jest.fn(),
|
|
};
|
|
|
|
Object.defineProperty(window, 'location', {
|
|
value: mockLocation,
|
|
writable: true,
|
|
});
|
|
|
|
// Suppress console errors during tests (optional, comment out for debugging)
|
|
const originalConsoleError = console.error;
|
|
const originalConsoleWarn = console.warn;
|
|
|
|
beforeAll(() => {
|
|
console.error = (...args: any[]) => {
|
|
// Filter out known React warnings during tests
|
|
if (
|
|
typeof args[0] === 'string' &&
|
|
(args[0].includes('Warning: ReactDOM.render is no longer supported') ||
|
|
args[0].includes('Warning: An update to') ||
|
|
args[0].includes('act(...)'))
|
|
) {
|
|
return;
|
|
}
|
|
originalConsoleError.call(console, ...args);
|
|
};
|
|
|
|
console.warn = (...args: any[]) => {
|
|
// Filter out known warnings
|
|
if (
|
|
typeof args[0] === 'string' &&
|
|
args[0].includes('componentWillReceiveProps')
|
|
) {
|
|
return;
|
|
}
|
|
originalConsoleWarn.call(console, ...args);
|
|
};
|
|
});
|
|
|
|
afterAll(() => {
|
|
console.error = originalConsoleError;
|
|
console.warn = originalConsoleWarn;
|
|
});
|