import '@testing-library/jest-dom/vitest'; import { afterEach } from 'vitest'; import { cleanup } from '@testing-library/react'; afterEach(() => cleanup()); // antd 的响应式组件依赖 matchMedia;jsdom 未实现。 if (!window.matchMedia) Object.defineProperty(window, 'matchMedia', { writable: true, value: (query: string) => ({ matches: false, media: query, onchange: null, addListener() {}, removeListener() {}, addEventListener() {}, removeEventListener() {}, dispatchEvent: () => false, }), }); if (!window.ResizeObserver) window.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} } as unknown as typeof ResizeObserver; // jsdom 的 getComputedStyle 不支持伪元素参数,antd 会调用并打印告警。 const original = window.getComputedStyle; window.getComputedStyle = (element: Element) => original(element);