Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda