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

176
Views
JEST - check if objects array is a subset of another array

Using JEST I want to test if an array of objects is a subset of another array.

I want to test the following:

const users = [{id: 1, name: 'Hugo'}, {id: 2, name: 'Francesco'}, {id: 3, name: 'Carlo'}];
const subset = [{id: 1, name: 'Hugo'}, {id: 2, name: 'Francesco'}];

expect(users).toContain(subset)

I've tried the following:

describe('test 1', () => {
  it('test 1', () => {
    expect(users).toEqual(
      expect.arrayContaining([
        expect.objectContaining(subset)
      ])
    )
  });
});

But this is not correct since objectContaining doesn't accept array as param ... it works only if subset is a single object.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I've never tried this myself, but wouldn't it work to just say:

expect(users).toEqual(
  expect.arrayContaining(subset)
)
about 4 years ago · Santiago Trujillo 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!