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

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

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