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

281
Vistas
Jest truncates list of received mock calls

I have a test that calls a spy multiple times:

// example.test.js
it("Fails but doesn't log all calls", () => {
  const spy = jest.fn();
  spy("1");
  spy("2");
  spy("3");
  spy("4");
  spy("5");
  expect(spy).toHaveBeenCalledWith("not 1");
});

Jest truncates the output, so only the first 3 calls are listed under Received:

// jest example.test.js
expect(jest.fn()).toHaveBeenCalledWith(...expected)

Expected: "not 1"
Received
        1: "1"
        2: "2"
        3: "3"

Number of calls: 5

  10 |   spy("4");
  11 |   spy("5");
> 12 |   expect(spy).toHaveBeenCalledWith("not 1");
      |               ^
  13 | });
  14 |

How can I get the full list of calls to show in the terminal for assertion failures?

Received
        1: "1"
        2: "2"
        3: "3"
        4: "4"
        5: "5"
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can just log to your console the mock calls"

const spy = jest.fn();
  spy("1");
  spy("2");
  spy("3");
  spy("4");
  spy("5");

  console.log(spy.mock.calls)

DOCS -> https://jestjs.io/docs/mock-functions

about 4 years ago · Juan Pablo Isaza Denunciar

0

As of June 2022, it is not possible using built-in jest assertions:

const PRINT_LIMIT = 3

Workaround: Write a custom assertion error. See logCalls:

import { printReceived } from "jest-matcher-utils";

const logCalls = (spy) => {
  const receivedCalls = spy.mock.calls.map((call, i) => 
    `${i}: ${printReceived(call)}`
  )
  console.error(`All Received:\n${receivedCalls.join("\n")}`)
}

it("Fails and logs all calls", () => {
  const spy = jest.fn();
  spy("1");
  spy("2");
  spy("3");
  spy("4");
  spy("5");

  try {
    expect(spy).toHaveBeenCalledWith("not 1");
  } catch (e) {
    logCalls(spy)
    throw e
  }
});

Which will output the following error:

All Received:
    0: ["1"]
    1: ["2"]
    2: ["3"]
    3: ["4"]
    4: ["5"]
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