diff --git a/src/components/ui/HoverCard/tests/HoverCard.lazyMount.test.tsx b/src/components/ui/HoverCard/tests/HoverCard.lazyMount.test.tsx new file mode 100644 index 000000000..932ec74a1 --- /dev/null +++ b/src/components/ui/HoverCard/tests/HoverCard.lazyMount.test.tsx @@ -0,0 +1,50 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import Theme from '~/components/ui/Theme/Theme'; +import HoverCard from '../HoverCard'; + +const mockMatchMedia = () => { + if ('matchMedia' in window && typeof window.matchMedia === 'function') return; + Object.defineProperty(window, 'matchMedia', { + writable: true, + value: jest.fn().mockImplementation(() => ({ + matches: false, + addEventListener: jest.fn(), + removeEventListener: jest.fn() + })) + }); +}; + +describe('HoverCard lazy mount', () => { + beforeEach(() => mockMatchMedia()); + + test('does not mount content until opened', () => { + render( + + + Trigger + + Hover body + + + + ); + + expect(screen.queryByTestId('hover-content')).not.toBeInTheDocument(); + }); + + test('mounts content when open', () => { + render( + + + Trigger + + Hover body + + + + ); + + expect(screen.getByText('Hover body')).toBeInTheDocument(); + }); +});