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

178
Views
Chai Assertion Error for Array Object Comparison

I am trying to compare 2 arrays where first array response is following:

   response= [
      {    
        organization: {
          id: '75f1e2e1-83eb-484e-bdaf-1da9b57c635d'   
      },
      {    
        organization: {
          id: '810d0465-2917-4d67-802a-69cda41647ad'
        
      }
    ]

second array

 expectedResponse=   [
      {    
        organization: {
          id: '75f1e2e1-83eb-484e-bdaf-1da9b57c635d'   
      }  
    ]

The function I wrote to compare 2 arrays for assertion is following

 response.body.forEach(function (index) {      
       expect(response.body[index].organization.id).to.eql(
        expectedResponse[index].organization.id
       );

But it is failing with error TypeError: Cannot read property 'organization' of undefined Not sure what i am doing wrong

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

when the index = 2 then expectedResponse[2] will result in null which will cause

TypeError: Cannot read property 'organization' of undefined

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!