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

141
Vistas
How can I print a pretty object diff in a Jest custom matcher?

I'm writing a custom Jest matcher to compare objects in some arbitrary way:

expect.extend({
  toTorgle(received, expected) {
    ...
    return {
      pass: false,
      message: () => "expect(received).toTorgle(expected):" + ???
    }
  }
})

How can I print a nice object diff between the two objects, like the one that I get with (built-in matcher) expect(received).toEqual(expected)?

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

0

According to Jest-Platform document, you can use jest-diff to get a "pretty-printed" string illustrating the difference between the two arguments.

Your message function will become:

const { diff } = require('jest-diff'); // already available if Jest is installed

// ...

message: () => "expect(received).toTorgle(expected):" + diff(received, expected),
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