setup.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import '@testing-library/jest-dom';
  2. import { vi } from 'vitest';
  3. // Mock ResizeObserver
  4. global.ResizeObserver = vi.fn().mockImplementation(() => ({
  5. observe: vi.fn(),
  6. unobserve: vi.fn(),
  7. disconnect: vi.fn(),
  8. }));
  9. // Mock IntersectionObserver
  10. global.IntersectionObserver = vi.fn().mockImplementation(() => ({
  11. observe: vi.fn(),
  12. unobserve: vi.fn(),
  13. disconnect: vi.fn(),
  14. }));
  15. // Mock scrollIntoView
  16. Element.prototype.scrollIntoView = vi.fn();
  17. // Mock window.matchMedia
  18. Object.defineProperty(window, 'matchMedia', {
  19. writable: true,
  20. value: vi.fn().mockImplementation(query => ({
  21. matches: false,
  22. media: query,
  23. onchange: null,
  24. addListener: vi.fn(),
  25. removeListener: vi.fn(),
  26. addEventListener: vi.fn(),
  27. removeEventListener: vi.fn(),
  28. dispatchEvent: vi.fn(),
  29. })),
  30. });
  31. // Mock localStorage
  32. const localStorageMock = {
  33. getItem: vi.fn(),
  34. setItem: vi.fn(),
  35. removeItem: vi.fn(),
  36. clear: vi.fn(),
  37. length: 0,
  38. key: vi.fn(),
  39. };
  40. Object.defineProperty(window, 'localStorage', {
  41. value: localStorageMock,
  42. });
  43. // Mock axios
  44. vi.mock('axios', () => ({
  45. default: {
  46. create: vi.fn(() => ({
  47. get: vi.fn(),
  48. post: vi.fn(),
  49. put: vi.fn(),
  50. delete: vi.fn()
  51. }))
  52. }
  53. }));
  54. // Mock sonner toast
  55. vi.mock('sonner', () => ({
  56. toast: {
  57. success: vi.fn(),
  58. error: vi.fn(),
  59. info: vi.fn(),
  60. warning: vi.fn()
  61. }
  62. }));