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

217
Visualizações
How to use Chai-jQuery's expect().to.match() assertion in Cypress? The BDD assertion with the same name gets used instead

I want to use the Chai-jQuery .match assertion:

// from Cypress docs: 
// match(selector)  
expect($emptyEl).to.match(':empty')

But the problem is, that a BDD Assertion with the same name exists:

// from Cypress docs: 
// match(RegExp)
expect('testing').to.match(/^test/)

I want to use the first one, but I can't figure out how - each time the BDD assertion gets used instead and throws an error. For example:

expect(cy.get('div')).to.match('#someId')

match requires its argument be a RegExp. You passed: #someId

I tried passing many different things into the expect() call in hopes of triggering a different overload, but I always get this error.

So what do I need to do to use the Chai-jQuery .match aseertion?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think Cypress choses the .match() version from the type passed to the expect() part.

With this fragment

<div id="someId">some text</div>

this will pass

cy.get('div').then($el => {

  expect($el).to.match('#someId')  // $el is type object, 
                                   // so match will be from chai-jQuery

  expect($el.text()).to.match(/some text/)  // $el.text() is type string, 
                                            // so match will be from chai
})

// Same applies with .should() wrapper

cy.get('div').should('match', '#someId')

cy.get('div').invoke('text').should('match', /some text/)

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