Search code examples
cypress

Cypress Testing - Expect input to be empty


I have an text input field that i would like cypress to check if it's empty.

I've tried:

    cy.get('[data-cy=inputField]').should('not.have.value');

    cy.get('[data-cy=inputField]').should('be.empty');

both tests pass even though even though there is text in the field.


Solution

  • I've found the solution. It works when i expect it to have the value of an empty string.

    cy.get('[data-cy=inputField]').should('have.value', '');