setup.ts 836 B

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