Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Cypress has no built-in cy.hover() command. If your application responds to a JavaScript mouse event, select the element and use .trigger('mouseover'), then assert the visible result. To target the child’s immediate parent, chain .parent() before triggering the event.

That dispatches an event; it does not reproduce every effect of moving a real pointer through the page. The right test depends on where the application’s handler is attached and whether its behavior requires a particular pointer path.

Trigger a hover handler on a child element

Use Cypress’s .trigger() command when the behavior you want to test is handled by an event listener such as mouseover. The selector and expected menu below are examples; replace them with selectors from your application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cy.get('[data-cy="child"]').trigger('mouseover')

cy.get('[data-cy="child-menu"]').should('be.visible')

The assertion checks the outcome that matters to a user—the child menu becoming visible—instead of treating the event dispatch itself as proof that the interface worked.

Hover the child’s immediate parent

When the handler belongs to the child’s parent, select the child and move one DOM level upward with .parent(). Cypress documents .parent() as a one-level query, so this targets the immediate parent, not every ancestor.

cy.get('[data-cy="child"]')
  .parent()
  .trigger('mouseover')

cy.get('[data-cy="parent-menu"]').should('be.visible')

If the test starts from the parent instead, query the intended child from that parent using a child query appropriate to the DOM relationship. Be precise about whether the target is a direct child or a deeper descendant: selecting the wrong level can dispatch the event to an element that does not own the relevant behavior.

Choose the interaction that matches the application

Before writing the command, identify what “hover” means in the component under test. A handler may be attached to the child, its immediate parent, or both. The expected result might be a menu, tooltip text, or another state. Select the element that receives the relevant event and assert that specific result.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Application behavior Test focus
A JavaScript handler responds to mouseover on the child Trigger mouseover on the child and assert the child’s expected state.
A handler responds on the immediate parent Select the child, call .parent(), trigger the event, and assert the parent-controlled state.
The interface depends on movement through nested elements Check whether the pointer path matters; a single event dispatch may not exercise the required interaction.

Cypress describes .trigger() as low-level event dispatch: it invokes the corresponding event listeners but does not perform all browser default actions. As the Cypress documentation puts it, “.trigger() will only fire the corresponding event and do nothing else.” Use that distinction to decide whether dispatching an event is sufficient for the behavior you are testing.

Understand what the test does—and does not—prove

A successful .trigger('mouseover') call shows that Cypress dispatched that event to the selected element. It does not, by itself, prove that a user moving a physical pointer through the page would produce the same result. Cypress’s interaction guidance describes cases where the order and path of mouse movement matter in nested navigation.

For a component whose behavior depends on such movement, test the actual resulting UI state and use an interaction approach that matches the implementation. Do not assume one dispatched event recreates a complete pointer journey. The available guidance establishes the event-dispatch distinction, but does not prescribe a universal command for every pointer-path-dependent interface.

Diagnose a hover test that does not work

  • Nothing changes: Confirm which element owns the handler and whether the application responds to mouseover. Triggering an event on a child will not test a handler attached only to its parent.
  • The wrong menu or state changes: Check the selector and DOM relationship. .parent() moves exactly one level upward; it does not select an arbitrary ancestor.
  • The event runs but the UI is still wrong: Assert the intended visible state or content. Event dispatch and successful application behavior are separate things.
  • Cypress reports an actionability error: Review the command error and the target’s current state. Cypress applies actionability checks to .trigger(); its documentation’s mouseover example includes visibility and enabled-state checks.
  • Nested navigation behaves differently from a real user interaction: Investigate whether it depends on movement sequence or pointer path. A single mouseover event does not model all browser actions.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API, not a replacement for a Cypress hover test. If you need a screenshot artifact of a URL instead of exercising the component interaction, one GET request can capture a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server provides screenshot tools for AI agents. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Learn about ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.

Documentation scope

The Cypress command behavior described here reflects official documentation reviewed on September 29, 2026. Cypress APIs can change, so check the current command and interaction documentation when working with a later release.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.