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

113
Vistas
Cypress test if input field value has multiple lines

I want to check with a cypress test if the value is correct in a single-line text fields and multi-line text area.

I here have a single line box where I use the code down below to add an input:

cy.followLabel("When did the incident happen?").type("single \nline");

Same thing for the multi line text area

cy.followLabel("Deenter code herescribe what happened").type("multiple \nlines");

enter image description here

I tried to validate it with .should() but haven't found any chainers that would suit my need.

Is there something like .contains("\n")?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Chai Assertion Library has a singleLine assertion in the chai-string module.

singleLine
assert.singleLine('abcdef');
expect('abcdef').to.be.singleLine();

To use assertions from other libraries, see Cypress recipe Adding Chai Assertions

Simple example

Install

yarn add -D chai-string

//or

npm install -D chai-string

Test

chai.use(require('chai-string'));

it('tests for singleLine', () => {

  cy.get('input')
    .type("single \nline")
    .invoke('val')
    .should('be.singleLine')  // passes

  cy.get('textarea')
    .type("multiple \nlines")
    .invoke('val')
    .should('not.be.singleLine')  // passes
})

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can directly check that the innerText has the new line character \n.

cy.get('selector').then(($ele) => {
  expect($ele).to.contain('\n')
})

In case your inner text doesn't have the newline characters, you assert the style tag containing overflow-wrap: break-word

cy.get('selector').should('have.attr', 'style').and('include', 'overflow-wrap: break-word')
about 4 years ago · Juan Pablo Isaza Denunciar

0

I know there is an assertion "match" for regex.

match(RegExp)
Aliases: matches    
expect('testing').to.match(/^test/)

(from https://docs.cypress.io/guides/references/assertions)

So in your case the regex could be match(/.*\n.*/gm)

about 4 years ago · Juan Pablo Isaza 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