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

165
Vistas
jest unit test javascript

I have a unit test I am trying check the field but cannot find anything in the jest documentation to ignore the one value in this case, randomNumber.

const expected = [
  {
    model: 'string',
    type: 'string',
    randomNumber: 43,
    name: 'string',
  },
]

The random number changes every test so I can't hard code the test to check that number. I would like to test to make sure the expected array has all of the fields, but ignore the values.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

const requiredKeys = ["model", "type", "randomNumber", "name"];

const actual = [
    {
      model: 'string',
      type: 'string',
      randomNumber: 43,
      name: 'string',
    },
    {    
      type: 'string',
      randomNumber: 43,
      name: 'string',
  },
]

actual.forEach(x => {
  const keys = Object.keys(x);
  const hasAllKeys = requiredKeys.every(key => keys.includes(key));

  expect(hasAllkeys).toBeTruthy();
});

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do something along the lines of this

const data =  {
    model: 'string',
    type: 'string',
    randomNumber: 43,
    name: 'string',
 }

const dataExpected = {
    model: 'string',
    type: 'string',
    name: 'string',
}

const {randomNumber, ...randomNumOmittedData} = data;

expect(randomNumOmittedData).toEqual(dataExpected);


about 4 years ago · Juan Pablo Isaza 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