setupTests.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import "@testing-library/jest-dom"
  2. import { setupI18nForTests } from "./i18n/test-utils"
  3. // Set up i18n for all tests
  4. setupI18nForTests()
  5. // Mock crypto.getRandomValues
  6. Object.defineProperty(window, "crypto", {
  7. value: {
  8. getRandomValues: function (buffer: Uint8Array) {
  9. for (let i = 0; i < buffer.length; i++) {
  10. buffer[i] = Math.floor(Math.random() * 256)
  11. }
  12. return buffer
  13. },
  14. },
  15. })
  16. // Mock matchMedia
  17. Object.defineProperty(window, "matchMedia", {
  18. writable: true,
  19. value: jest.fn().mockImplementation((query) => ({
  20. matches: false,
  21. media: query,
  22. onchange: null,
  23. addListener: jest.fn(), // deprecated
  24. removeListener: jest.fn(), // deprecated
  25. addEventListener: jest.fn(),
  26. removeEventListener: jest.fn(),
  27. dispatchEvent: jest.fn(),
  28. })),
  29. })
  30. // Mock lucide-react icons globally using Proxy for dynamic icon handling
  31. jest.mock("lucide-react", () => {
  32. return new Proxy(
  33. {},
  34. {
  35. get: function (_obj, prop) {
  36. // Return a component factory for any icon that's requested
  37. if (prop === "__esModule") {
  38. return true
  39. }
  40. return (props: any) => (
  41. <div {...props} data-testid={`${String(prop)}-icon`}>
  42. {String(prop)}
  43. </div>
  44. )
  45. },
  46. },
  47. )
  48. })