Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

99
Vistas
.type() method in cypress when string is empty

Sometimes I want to pass empty string to .type() and I'm getting an error, for instance:

data = {
  "test1": "test",
  "test2": "",
};

and when I assigned first case it's work:

cy.get(...).type("test1")

The output:

test1

But when I'm passing the next one, just empty string:

cy.get(...).type("")

I've got an error that I can't provide empty string. How can I fix that?

This snippet of code is a part of a function so it must works for empty string as well as not empty string.

I tried something like this:

cy.get(...).type('{backspace}', variable)

it's working when string is empty but also skipping variable if variable contain characters.

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

It's not possible for a user to type "", so neither can your test.

Use cy.get(...).clear() to make it empty.

about 4 years ago · Santiago Trujillo Denunciar

0

From the comments, looks like you have already come to the solution

For example,

for (const key in data) {
  cy.get(key).type(data[key])     // fails when data[key] is empty
}

could be fixed with

for (const key in data) {
  if (data[key]) {
    cy.get(key).type(data[key])   // only type non-empty data values
  }
}
about 4 years ago · Santiago Trujillo Denunciar

0

I found the answer on my own in other resources

let array = ['test1', '', 'test2', 'test3']

for (let item in array) {
  cy.get(...).type(`{backspace}` + `${item}`)
}

and its work, even if string is empty.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda