setup.ts 1018 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import '@testing-library/jest-dom';
  2. import { vi } from 'vitest';
  3. // Mock sonner
  4. vi.mock('sonner', () => ({
  5. toast: {
  6. success: vi.fn(),
  7. error: vi.fn(),
  8. warning: vi.fn(),
  9. info: vi.fn()
  10. }
  11. }));
  12. // Mock scrollIntoView for Radix UI components
  13. Element.prototype.scrollIntoView = vi.fn();
  14. // Mock pointer events for Radix UI Select component
  15. Element.prototype.hasPointerCapture = vi.fn(() => true) as any;
  16. Element.prototype.releasePointerCapture = vi.fn() as any;
  17. Element.prototype.setPointerCapture = vi.fn() as any;
  18. // Mock IntersectionObserver
  19. global.IntersectionObserver = vi.fn().mockImplementation(() => ({
  20. observe: vi.fn(),
  21. unobserve: vi.fn(),
  22. disconnect: vi.fn()
  23. })) as any;
  24. // Mock ResizeObserver (使用 class 模式以支持 Radix UI 的 react-use-size)
  25. global.ResizeObserver = class MockResizeObserver {
  26. constructor(callback: ResizeObserverCallback) {
  27. // Store callback for testing
  28. (this as any).callback = callback;
  29. }
  30. observe() {}
  31. unobserve() {}
  32. disconnect() {}
  33. };