Cypress `.type` enters same text twice (duplicating each letter)

Viewed 349

I have a cypress test that uses cy.get(...).clear().type('some-text'). When it runs, it sometimes works as expected, and sometimes enters ssoommee--tteexxtt instead of some-text. Yes, each letter is entered twice. This seems to be happening roughly 50% of the time.

I have other tests that use .type(...), none of which present this behavior. Only the first test using .type(...) does this.

1 Answers

Inspecting the surrounding tests, I found a stray async on the test right before the flaky one:

    it('Tests some element', async () => {
        cy.visit('/')
        cy.get('[id="some-element"]').should('exist')
    })
    
    it('Types into a text box', () => {
        cy.visit('/')
        cy.get('input[name="q"]').clear().type('some-text')
        ...
    })

That async on the previous test was the culprit! Removing it sorted it all out.

Related