: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
import { act, renderHook } from '@testing-library/react'
import { useHoverIntent } from './useHoverIntent'
describe('useHoverIntent', () => {
beforeEach(() => {
jest.useFakeTimers()
})
afterEach(() => {
jest.useRealTimers()
})
it.each([
{ name: 'a resting pointer', leaveAfterMs: null, calls: 1 },
{ name: 'a pointer that passes over', leaveAfterMs: 50, calls: 0 },
])('calls back once for $name', ({ leaveAfterMs, calls }) => {
const onIntent = jest.fn()
const { result, unmount } = renderHook(() => useHoverIntent(onIntent, 120))
act(() => result.current.start())
if (leaveAfterMs !== null) {
act(() => jest.advanceTimersByTime(leaveAfterMs))
act(() => result.current.cancel())
}
act(() => jest.advanceTimersByTime(500))
unmount()
expect(onIntent).toHaveBeenCalledTimes(calls)
})
})