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

131
Vistas
Jest cuts off received array

I use Jest to test if a large array contains a given value:

it('should contain x', () => {
  const myArray: string[] = myFunction();

  expect(myArray).toContain('x');
});

When the test fails, Jest cuts off the received array:

Expected value: "x"
Received array: ["a", "b", "c", "d", "e", "f", "g", "h", ...]

This makes it difficult for me to check why the test failed. Can I force Jest force to print the entire received array instead of cutting it off?

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

0

You could check this answer.

In your specific use case, I would:

describe("log long array", () => {
  it("logs long array", () => {
    const testArray: number[] = Array.from(Array(10000).keys()),
      expectedNumber = 99999999;

    try {
      expect(testArray).toContain(expectedNumber);
    } catch {
      console.log("Test failed! Array:", JSON.stringify(testArray));
      expect(testArray).toContain(expectedNumber);
    }
  });
});

You could also catch and log the error if you want

Note that I'm calling the same expect twice, as I still want to have the normal Jest behavior for my failing test

Alternatively, you could look into extending jest, allowing expect to have custom error messages with, for example, this package, or creating a custom matcher (docs here)

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