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

107
Vistas
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 Respuestas
Responde la pregunta

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 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