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

237
Views
How to check if array contains defined values using supertest?

Let's say in response during tests I have such array:

array = [
 'a',   'b',
 'c',   'd',
 'e',   'f',
 'g',   'h',
 'i',   'j'
]

And I want to check if this array really contains those values:

array.should.be.a.Array()
.with.lengthOf(response.body.length)
.and.have.properties('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');

As you can see I can't use here have.properties because it's array, not object. So, how can I check ?

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

0

You can use should.deepEqual to match length and values with order

const arr = [
 'a',   'b',
 'c',   'd',
 'e',   'f',
 'g',   'h',
 'i',   'j'
];

arr.should.deepEqual(arr);
console.log("test passed");
<script src="https://cdnjs.cloudflare.com/ajax/libs/should.js/13.2.3/should.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report

0

If you need an exact match go with Chandan's answer, if you need to match a subset, you can use should.containDeep (see the docs). Here's an example:

const arr = [
 'a',   'b',
 'c',   'd',
 'e',   'f',
 'g',   'h',
 'i',   'j'
];

arr.should.containDeep(['a', 'b', 'c', 'd']);
console.log("test passed");
<script src="https://cdnjs.cloudflare.com/ajax/libs/should.js/13.2.3/should.min.js"></script>

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!