:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(lemon-ui): regression test for LemonDropdown non-Node relatedTarget (#64958)
posthog[bot]1a80089a4d0a
diff --git a/frontend/src/lib/lemon-ui/LemonDropdown/LemonDropdown.test.tsx b/frontend/src/lib/lemon-ui/LemonDropdown/LemonDropdown.test.tsxnew file mode 100644index 000000000000..b0acfd0573ff--- /dev/null+++ b/frontend/src/lib/lemon-ui/LemonDropdown/LemonDropdown.test.tsx@@ -0,0 +1,45 @@+import '@testing-library/jest-dom'++import { cleanup, fireEvent, render, screen } from '@testing-library/react'++import { LemonDropdown } from './LemonDropdown'++describe('LemonDropdown', () => {+ // jest.setupAfterEnv does not enable RTL auto-cleanup; unmount between tests so the portal stays isolated.+ afterEach(() => {+ cleanup()+ })++ // `e.relatedTarget` on a mouseleave is null when the cursor leaves the document and can be a+ // non-Node (the Window) when it exits the viewport — both used to reach `Node.contains()` and+ // throw "parameter 1 is not of type 'Node'". The overlay must be open so the refs are populated.+ it.each([+ { desc: 'null relatedTarget', relatedTarget: null },+ { desc: 'non-Node relatedTarget (window)', relatedTarget: window },+ ])('does not throw on a hover mouseleave with $desc', ({ relatedTarget }) => {+ const onVisibilityChange = jest.fn()++ render(+ <LemonDropdown+ trigger="hover"+ startVisible+ onVisibilityChange={onVisibilityChange}+ overlay={<div>Menu</div>}+ >+ <button>Open</button>+ </LemonDropdown>+ )++ const trigger = screen.getByRole('button', { name: 'Open' })+ const overlay = document.querySelector('.Popover')+ expect(overlay).toBeInTheDocument()++ // Child trigger's onMouseLeave (guards against floatingRef.current.contains).+ expect(() => fireEvent.mouseLeave(trigger, { relatedTarget })).not.toThrow()+ // Overlay's onMouseLeaveInside (guards against referenceRef.current.contains).+ expect(() => fireEvent.mouseLeave(overlay!, { relatedTarget })).not.toThrow()++ // The "cursor has left" branch should still run, closing the dropdown.+ expect(onVisibilityChange).toHaveBeenCalledWith(false)+ })+})