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

103
Visualizações
cypress test asserting a filtering operation on array of objects expecting undefined

I have a cypress test over an API. When I do

cy.getUnits(u.email)

I'm expecting a 200 OK response similar to this in the body of the response

{
  “units”: [
 {
      “store: “US_1234567890”,
      “role”: “user”,
      “email”: “user1@gmail.com”
    },
   {
     “store: “CA_865890X”,
      “role”: “admin”,
     “email”: “user1@gmail.com”
   }
  ]
}

I'm expecting that list of units doesn't contain the unit "u" below

const u =    {
     “store: ” US_56890765",
      “role”: “admin”,
      “email”: “user1@gmail.com”
   }

So in cypress, I did

cy.getUnits(u.email)
 .should(response => expect(response.status).to.equal(200))
 .its(‘body’)
 .should(units => {
  expect(units.length).to.equal(2)
  units.filter(
   unit =>
    unit.email === u.email &&
    unit.role === u.role &&
    unit.store === u.store,
  ).should.be.undefined
 })

That is not working

units.filter(
       unit =>
        unit.email === u.email &&
        unit.role === u.role &&
        unit.store === u.store,
      ).should.be.undefined

I have tried different variations to no avail.

Could someone please help me find a solution to this?

I really appreciate any help you can provide.

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

0

You want to check the filtered array length

.should(units => {
  expect(units.length).to.equal(2)
  const filtered = units.filter(unit =>
    unit.email === u.email &&
    unit.role === u.role &&
    unit.store === u.store
  )
  expect(filtered).to.have.length(0)
})
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