Cypress: Mouse leave event not triggered

Created on 5 Mar 2019  路  3Comments  路  Source: cypress-io/cypress

Current behavior:

While .trigger('mouseover'); triggers onMouseEnter event but .trigger('mouseleave'); doesn't trigger onMouseLeave event (React app)

Desired behavior:

.trigger('mouseleave'); should trigger onMouseLeave event

Steps to reproduce: (app code and test code)

Checkout this stackblitz: https://stackblitz.com/edit/react-dmfnux?file=index.js
"Enter" and "leave" events both work well

Try this test

context('Hovering', () => {
  it('should load properly', () => {
    cy.visit('https://react-dmfnux.stackblitz.io');
    cy.get('#target', { timeout: 60000 }).should('be.visible');
  });

  it('should trigger mouseleave event', () => {
    cy.get('#target').trigger('mouseover');
    cy.get('#text').should('contain', 'enter');
    cy.get('#target').trigger('mouseleave');
    cy.get('#text').should('contain', 'leave');
  });
});

and see it fail

capture d ecran 2019-03-05 a 10 59 04

Versions

Chrome 72, Mac OS Mojave, Cypress 3.1.5

Most helpful comment

Your app is listening for mouseout as shown here:

image

React does this under the hood, when you set onMouseEnter/onMouseLeave, it listens on mouseover/mouseout.

All 3 comments

Your app is listening for mouseout as shown here:

image

React does this under the hood, when you set onMouseEnter/onMouseLeave, it listens on mouseover/mouseout.

Thanks @Bkucera !

Thank you @Bkucera :)

Was this page helpful?
0 / 5 - 0 ratings