Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!