1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/frontend/src/setupTests.ts
Nuno Góis ffcfe85575
chore: scroll-related UX adjustments in the Unleash AI chat (#8478)
https://linear.app/unleash/issue/2-2857/make-some-scroll-related-ux-adjustments-to-the-unleash-ai-chat

Introduces scroll-related UX enhancements to the Unleash AI chat,
providing a smoother and more refined user experience.
2024-10-18 14:38:46 +01:00

72 lines
1.8 KiB
TypeScript

import '@testing-library/jest-dom';
import 'whatwg-fetch';
import 'regenerator-runtime';
import { beforeAll, vi } from 'vitest';
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
class IntersectionObserver {
root: any;
rootMargin: any;
thresholds: any;
observe() {}
unobserve() {}
disconnect() {}
takeRecords() {
return [];
}
}
if (!window.ResizeObserver) {
window.ResizeObserver = ResizeObserver;
}
if (!window.IntersectionObserver) {
window.IntersectionObserver = IntersectionObserver;
}
process.env.TZ = 'UTC';
const errorsToIgnore = [
'Warning: An update to %s inside a test was not wrapped in act',
"Failed to create chart: can't acquire context from the given item",
];
const warningsToIgnore = [
'[MSW] Found a redundant usage of query parameters in the request handler URL for',
'MUI: You have provided an out-of-range value',
];
const logsToIgnore = ['An exception was caught and handled.'];
// ignore known React warnings
const consoleError = console.error;
const consoleWarn = console.warn;
const consoleLog = console.log;
beforeAll(() => {
const shouldIgnore = (messagesToIgnore: string[], args: any[]) =>
typeof args[0] === 'string' &&
messagesToIgnore.some((msg) => args[0].includes(msg));
vi.spyOn(console, 'error').mockImplementation((...args) => {
if (!shouldIgnore(errorsToIgnore, args)) {
consoleError(...args);
}
});
vi.spyOn(console, 'warn').mockImplementation((...args) => {
if (!shouldIgnore(warningsToIgnore, args)) {
consoleWarn(...args);
}
});
vi.spyOn(console, 'log').mockImplementation((...args) => {
if (!shouldIgnore(logsToIgnore, args)) {
consoleLog(...args);
}
});
});