vitest.setup.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import "@testing-library/jest-dom"
  2. import "@testing-library/jest-dom/vitest"
  3. class MockResizeObserver {
  4. observe() {}
  5. unobserve() {}
  6. disconnect() {}
  7. }
  8. global.ResizeObserver = MockResizeObserver
  9. // Fix for Microsoft FAST Foundation compatibility with JSDOM
  10. // FAST Foundation tries to set HTMLElement.focus property, but it's read-only in JSDOM
  11. // The issue is that FAST Foundation's handleUnsupportedDelegatesFocus tries to set element.focus = originalFocus
  12. // but JSDOM's HTMLElement.focus is a getter-only property
  13. Object.defineProperty(HTMLElement.prototype, "focus", {
  14. get: function () {
  15. return (
  16. this._focus ||
  17. function () {
  18. // Mock focus behavior for tests
  19. }
  20. )
  21. },
  22. set: function (value) {
  23. this._focus = value
  24. },
  25. configurable: true,
  26. })
  27. Object.defineProperty(window, "matchMedia", {
  28. writable: true,
  29. value: vi.fn().mockImplementation((query) => ({
  30. matches: false,
  31. media: query,
  32. onchange: null,
  33. addListener: vi.fn(),
  34. removeListener: vi.fn(),
  35. addEventListener: vi.fn(),
  36. removeEventListener: vi.fn(),
  37. dispatchEvent: vi.fn(),
  38. })),
  39. })
  40. // Mock scrollIntoView which is not available in jsdom
  41. Element.prototype.scrollIntoView = vi.fn()
  42. // Suppress console.log during tests to reduce noise.
  43. // Keep console.error for actual errors.
  44. const originalConsoleLog = console.log
  45. const originalConsoleWarn = console.warn
  46. const originalConsoleInfo = console.info
  47. console.log = () => {}
  48. console.warn = () => {}
  49. console.info = () => {}
  50. afterAll(() => {
  51. console.log = originalConsoleLog
  52. console.warn = originalConsoleWarn
  53. console.info = originalConsoleInfo
  54. })