Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda