vitest.setup.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import "@testing-library/jest-dom"
  2. import "@testing-library/jest-dom/vitest"
  3. // Force React into development mode for tests
  4. // This is needed to enable act(...) function in React Testing Library
  5. globalThis.process = globalThis.process || {}
  6. globalThis.process.env = globalThis.process.env || {}
  7. globalThis.process.env.NODE_ENV = "development"
  8. class MockResizeObserver {
  9. observe() {}
  10. unobserve() {}
  11. disconnect() {}
  12. }
  13. global.ResizeObserver = MockResizeObserver
  14. // Fix for Microsoft FAST Foundation compatibility with JSDOM
  15. // FAST Foundation tries to set HTMLElement.focus property, but it's read-only in JSDOM
  16. // The issue is that FAST Foundation's handleUnsupportedDelegatesFocus tries to set element.focus = originalFocus
  17. // but JSDOM's HTMLElement.focus is a getter-only property
  18. Object.defineProperty(HTMLElement.prototype, "focus", {
  19. get: function () {
  20. return (
  21. this._focus ||
  22. function () {
  23. // Mock focus behavior for tests
  24. }
  25. )
  26. },
  27. set: function (value) {
  28. this._focus = value
  29. },
  30. configurable: true,
  31. })
  32. Object.defineProperty(window, "matchMedia", {
  33. writable: true,
  34. value: vi.fn().mockImplementation((query) => ({
  35. matches: false,
  36. media: query,
  37. onchange: null,
  38. addListener: vi.fn(),
  39. removeListener: vi.fn(),
  40. addEventListener: vi.fn(),
  41. removeEventListener: vi.fn(),
  42. dispatchEvent: vi.fn(),
  43. })),
  44. })
  45. // Mock scrollIntoView which is not available in jsdom
  46. Element.prototype.scrollIntoView = vi.fn()