How to click and hold in cypress?

Viewed 2796

I have a username/password input with a 'show password' button which shows the password text when clicked; but only if you hold it. As soon as you release the click, it will hide the password again.

The wrong way of testing it is:

  it('show password word', () => {
    cy.get('[data-cy="login-password-input"]').should('have.type', 'password')
    cy.get('[data-cy="show-password-btn"]').click()
    cy.get('[data-cy="login-password-input"]').should('have.type', 'text')
  })

Since this reverts back to type=password before I have a chance to check it. Is it possible to keep the click held down whilst performing the last verification check?

3 Answers
cy.get('[data-cy="show-password-btn"]').trigger('mousedown', {
  button: 0
})
Related