blob: 665628f4cc48124b0320fded763739e1918cf75e [file]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Test setup file for Jest and React Testing Library */
import '@testing-library/jest-dom';
// Mock ResizeObserver
(global as any).ResizeObserver = class ResizeObserver {
constructor(cb: any) {
this.callback = cb;
}
callback: any;
observe() {
// Mock implementation
}
unobserve() {
// Mock implementation
}
disconnect() {
// Mock implementation
}
};
// Mock IntersectionObserver
(global as any).IntersectionObserver = class IntersectionObserver {
constructor(cb: any) {
this.callback = cb;
}
callback: any;
root = null;
rootMargin = '';
thresholds = [];
observe() {
// Mock implementation
}
unobserve() {
// Mock implementation
}
disconnect() {
// Mock implementation
}
takeRecords() {
return [];
}
};
// Mock window.matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(), // deprecated
removeListener: jest.fn(), // deprecated
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
})),
});
// Mock getComputedStyle
Object.defineProperty(window, 'getComputedStyle', {
value: () => ({
display: 'none',
appearance: ['-webkit-appearance']
})
});
// Mock HTMLCanvasElement.getContext
HTMLCanvasElement.prototype.getContext = jest.fn();
// Polyfill structuredClone for Jest environment
(global as any).structuredClone = (global as any).structuredClone || ((obj: any) => {
return JSON.parse(JSON.stringify(obj));
});
// Mock console methods in test environment
const originalError = console.error;
const originalWarn = console.warn;
beforeAll(() => {
console.error = (...args: any[]) => {
if (
typeof args[0] === 'string' &&
args[0].includes('Warning: ReactDOM.render is deprecated')
) {
return;
}
originalError.call(console, ...args);
};
console.warn = (...args: any[]) => {
if (
typeof args[0] === 'string' &&
args[0].includes('componentWillReceiveProps has been renamed')
) {
return;
}
originalWarn.call(console, ...args);
};
});
afterAll(() => {
console.error = originalError;
console.warn = originalWarn;
});