setup.ts 961 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import '@testing-library/jest-dom';
  2. import { afterEach, vi } from 'vitest';
  3. import { cleanup } from '@testing-library/react';
  4. // 在每个测试后清理
  5. afterEach(() => {
  6. cleanup();
  7. });
  8. // Mock window.matchMedia
  9. Object.defineProperty(window, 'matchMedia', {
  10. writable: true,
  11. value: vi.fn().mockImplementation(query => ({
  12. matches: false,
  13. media: query,
  14. onchange: null,
  15. addListener: vi.fn(),
  16. removeListener: vi.fn(),
  17. addEventListener: vi.fn(),
  18. removeEventListener: vi.fn(),
  19. dispatchEvent: vi.fn(),
  20. })),
  21. });
  22. // Mock ResizeObserver - 需要调用callback以便Select组件正常工作
  23. global.ResizeObserver = class ResizeObserver {
  24. cb: any;
  25. constructor(cb: any) {
  26. this.cb = cb;
  27. }
  28. observe() {
  29. this.cb([{ borderBoxSize: { inlineSize: 0, blockSize: 0 } }]);
  30. }
  31. unobserve() {}
  32. disconnect() {}
  33. };
  34. // Mock Element.scrollIntoView 避免shadcn/ui Select组件错误
  35. Element.prototype.scrollIntoView = vi.fn();